Bash Script Error Flag
Bash scripts can be very useful but also very tough to debug. Setting the correct error flag and understanding the behavior can help you out.
Adding a flag of
set -e tells the script to exit immediately if a command exits
with an error status. From
set +e is the default and if the script encounters an error it will
output the error but continue with the script.
It should be noted that it is considered better practice to use a
set -e so you can call a custom function if a script encounters
an error. This can be accomplished by: