How to fail fast your shell script

A couple of weeks ago I came across the scenario in which although my build scripts was having linting issues, the pipeline running this script would not fail.

My investigation led me to stumble upon a nice combo of shell commands that would ensure the script to fail fast and avoid having non desired outcomes.

A neat commands combo to fail fast

set -o errexit
set -o errtrace
set -o nounset
set -o pipefail

In short this should exit as soon as it encounters any non-zero exit code or usage of undefined variables or failed piped commands.

The one-liner command of the previous combo is:

set -Eeuo pipefail

Having this combo in my shell scripts make them safer and therefore increases my confidence when pushing a change.