Bash Exit-Code and Pipefail Propagation Audit Prompt
Audit a Bash script for swallowed failures, missing pipefail, and broken exit-code propagation through pipes, subshells, and command substitution
- Target user
- engineers who automate ops with Bash and Python
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who hunts down the silent failures that make a script exit 0 while leaving the system broken. I will provide: - The Bash script and how it is invoked (cron, CI step, systemd unit) - What "success" must mean for this script downstream - Any commands whose nonzero exit I intentionally tolerate Your job: 1. **Trace every exit path** — identify where failures can be swallowed: unpiped commands without `set -e`, pipes without `pipefail`, `local x=$(cmd)` masking the status, subshells, and `&&`/`||` chains. 2. **Explain the propagation rule** — for each finding, state exactly why the nonzero status is or is not seen by `$?` and the caller. 3. **Rewrite the failures** — apply `set -euo pipefail`, split declaration from assignment, use `PIPESTATUS`, and add explicit checks where `set -e` does not fire. 4. **Preserve tolerated failures** — wrap intentionally non-fatal commands in `|| true` or guarded `if`, documenting why. 5. **Add a final exit contract** — ensure the script ends with a deterministic, meaningful exit code and a one-line summary of what each nonzero code means. Output as: a findings table (location, swallowed-failure mechanism, fix), the corrected snippets, and an exit-code legend. Default to surfacing failures loudly; never let a pipeline or command substitution hide a nonzero status from the caller.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Word-Splitting and Quoting Hardening Prompt
Audit and rewrite a Bash script to eliminate unquoted-expansion bugs, unsafe word splitting, and glob injection while preserving intended behavior
-
Bash getopts Long-Options Parser Prompt
Build a robust Bash option parser that supports both short flags and GNU-style long options with validation and a generated usage block
-
Bash Sourceable Function Library Pattern Prompt
Refactor scattered Bash helpers into a safe, namespaced, sourceable library that can be reused across scripts without polluting the caller's environment
-
Python venv pip-tools Pinned Bootstrap Prompt
Generate a reproducible virtualenv bootstrap that compiles fully pinned, hash-verified dependencies from a high-level requirements.in using pip-tools
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.