Today I learned about shell script exit on error

  • Written on: Th Jan 2021
  • Last update: Th Jan 2021

Exit on error in bash shell script

Today I learned that you should always prepend your shell scripts with set -e to make sure that If any of your commands fails, your script fails too and wont go further.

By default, if one of the commands fails with an exit code different than 0, your shell script wont stop and you won't notice if something went wrong.

Note that set -e is an alias of set -o errexit. It's probably better to use that one since it's more explicit than a simple "e" that you may not understand it's meaning.