Shell Scripting – set -euo pipefail Failsafe

Shell scripts don’t actually fail automatically. If one line returns a non-zero (failure) exit code, that code simply falls through to the next line, but the shell script keeps running.

For this reason, you’ll often want to use this at the top of your script:

set -euo pipefail

This tells the script that if any of the steps (not in a block construction) fail (exit with non-zero), the whole script should halt in place and the script will exit with the failure message of the failed step.