Plainnotes

set -e will not save your script

2025-10-08 · 2 min readTools

set -e looks like "exit on error", but the exceptions are numerous.

In a pipeline only the last command's status counts:

false | true
echo "still here"

-e does not fire, because true succeeded. Use set -o pipefail to catch any failure in the pipeline.

Commands inside if, while, && or || are exempt — POSIX says so, it is not a bug.

And subshells do not necessarily inherit it; (false; echo ok) prints ok.

The full shebang line is:

set -euo pipefail

-u catches unset variables, pipefail catches pipelines, -e the rest. Adding trap 'echo "failed at $LINENO"' ERR saves a lot of time.