Fail Fast in Bash With set -euo pipefail

Add a strict-mode header so scripts stop on unset variables and failing pipes.

macOSbashshellscriptingLow risk
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 pipefail

02What 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

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!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 page
    Debian · technical · 2026-09-20
    Evidence: The bash manual page documents the set builtin and its options.

Last verified: 2026-10-13 · Category: Developer