Fail Fast in Bash With set -euo pipefail
Add a strict-mode header so scripts stop on unset variables and failing pipes.
Put set -euo pipefail at the top of a script to exit on any error, unset variable or failed pipeline stage.
01Command
Command
$ set -euo pipefail02What it does
By default a shell script keeps going after a failed command, which turns small errors into bigger ones during automation. Strict mode makes -e exit on failure, -u reject unset variables and -o pipefail surface failures inside pipelines. There is no graphical equivalent, because this control over automation is exactly what shells provide.
03Risk
!Warning: Some commands legitimately return non-zero; guard them with || true or explicit if statements instead of removing strict mode.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- bash.1.en.html manual pageEvidence: The bash manual page documents the set builtin and its options.
Last verified: 2026-10-13 · Category: Developer