Bash Script With `set -e` Silently Ignored Failing Command in Pipe or `local`
Without `set -o pipefail`, only the rightmost command exit code counts; `local x=$(cmd)` also masks exit status.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Bash Script With `set -e` Silently Ignored Failing Command in Pipe or `local`
Platform: Linux
Common Root Causes:
- Without `set -o pipefail`, only the rightmost command exit code counts; `local x=$(cmd)` also masks exit status.
Interactive Diagnostic Checklist
Verified Solutions:
- Use `set -euo pipefail`, declare `local x` on a separate line from assignment, and lint with ShellCheck.
Safe Diagnostic Command:
shellcheck <script.sh>
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Without `set -o pipefail`, only the rightmost command exit code counts; `local x=$(cmd)` also masks exit status. Recommended diagnostic: `shellcheck <script.sh>`. Remediation: Use `set -euo pipefail`, declare `local x` on a separate line from assignment, and lint with ShellCheck.
Worked Examples
- Run `shellcheck <script.sh>` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-bash-set-e-pipefail-silent-mask · Independently verified: 2026-11-25