Skip to content

Making a bash script terminate when a command returns an error

#!/bin/bash -e
 
trap "echo ERROR HANDLING HERE." ERR
echo "Starting" 
asdfasdf
echo "End"

And when you run it:

Starting
piet.sh: line 5: asdfasdf: command not found
ERROR HANDLING HERE.
End


    No Comments ( Add comment / trackback )