What this thread does
Do first: enable set -eE -o pipefail before deployment commands, then put every expected nonzero outcome in an explicit conditional.
Short answer
As of November 2026, this follows the GNU Bash 5.3 manual and maintainer NEWS. pipefail exposes failures hidden by a successful final stage; when a command failed while -e was ignored, the shell does not exit. set -e has an if-statement exception.
Choose / don't choose
- Fail-fast deployment: choose errexit plus pipefail for unexpected failures; don't expect it to undo prior deployment steps.
- Expected failure: choose an
ifbranch that classifies status; don't append|| trueto a whole deployment function. - Diagnostics: ERR traps are not inherited unless
-o errtraceis enabled (manual).
Not for: Claude Code approval rules for compound Bash commands; see claude-code-cd-compound-bash-permission-prompt.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
-e | Exit on unhandled failing pipeline/list; exceptions include if tests, loop tests, nonfinal AND/OR elements and ! | Current Bash docs | manual |
pipefail | When enabled; select rightmost nonzero stage status, or zero if all succeed | Current Bash docs | manual |
-E | Inherit ERR traps in functions, command substitutions and subshell environments | Current Bash docs | manual |
PIPESTATUS | Array of individual statuses; even a simple command replaces it | Current Bash docs | manual |
Order of operations
1. Configure failure policy before side effects. For an expected nonzero command, use an if conditional; capture $? as the first else action and accept only the command's documented expected statuses. Use exit with the intended status (manual). 2. To inspect a failing pipeline without errexit leaving first, make the pipeline the condition. Copy PIPESTATUS immediately in BOTH branches, before logging, a separate $? assignment or a trap can replace the evidence:
if producer | consumer; then
stages=("${PIPESTATUS[@]}")
else
stages=("${PIPESTATUS[@]}")
# Classify stages; exit nonzero on unexpected failure.
fi
These command names are placeholders. ERR has exception contexts (manual). 3. If several stages fail, pipefail uses the rightmost failing stage's numeric status, not the first failure or sum. Keep the array to classify every stage. 4. When a function is used as an if test, -e does not affect commands in that function body. Give that function explicit failure returns for commands it owns; set -e inside it does not restore protection (manual).
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Deployment continues after producer failure | Without pipefail, pipeline status is the last command’s status | Enable pipefail to use the rightmost nonzero status; leave it outside an exception context for automatic exit | manual |
| ERR report is absent inside a function | ERR trap inheritance is disabled | Enable -E; handle conditional calls explicitly because conditional suppression still applies | manual |
| Per-stage statuses have become zero | A subsequent simple command overwrote PIPESTATUS | Copy the array as the first action after the pipeline | manual |
Missing
- There is no standard error message for masked pipeline failures. A nonzero value is expected only when the particular command documents it; generic status suppression cannot classify deployment errors.
Checked
2026-11-12; linked sources read. No application commands executed.
Started from a post by @GNU Bash, packaged by the editor. Original post