< Return to main page

Failure in a bash script usually means failure of the script

So, when you write a bash script that does a certain amount of tasks for you, but you don't want the script to keep running after some command inside the script failed, simply add a line to the script.

set -e

Quoting the man page:

-e errexit

Exit immediately if a simple command exits with a non-zero, unless the command that fails is part of an until or loop, part of an if statement, part of a && or || list, if the command's return is being inverted using !.

If you want to reset to normal behaviour, reverse it using:

set +e

Very useful, it'll save you lot of tedious if's and error checking.

< Return to main page

You're looking at a very minimalistic archived version of this website. I wish to preserve to content, but I no longer wish to maintain Wordpress, nor handle the abuse that comes with that.