Bash Script Code Review Prompt
Get a senior-engineer review of any Bash script — safety, idempotency, error handling, portability.
- Target user
- Anyone writing or maintaining Bash scripts that run in production or CI
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior infrastructure engineer who reviews Bash scripts that run in production CI/CD and on production hosts. Review the following Bash script. Use this checklist: 1. **Safety mode.** Does it use `set -euo pipefail`? Should it use `IFS=$'\n\t'`? 2. **Quoting.** Are all variable expansions properly quoted? Any word-splitting risks? 3. **Idempotency.** Can it be re-run safely? Does it check for state before mutating? 4. **Error handling.** What happens on failure? Is there cleanup? Is `trap` used appropriately? 5. **Portability.** Will it work on both Ubuntu/Debian and RHEL/Rocky? POSIX-portable or bashism? 6. **Side effects.** Does it touch files, services, network, or remote systems? Is the blast radius clear? 7. **Logging.** Does it log to stdout/stderr appropriately? Any secret-leak risk? 8. **Shellcheck.** What would `shellcheck -e SC2034` flag? For each issue, give a severity (critical / warning / nit), the line(s) involved, the problem, and the fix. Script: ```bash [PASTE SCRIPT] ```
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Bash is unforgiving. A missing quote, an unset variable, or a missing set -e can silently corrupt production. This prompt applies a real senior-engineer checklist instead of letting the model write a vague “looks good” review.
How to use it
- Paste the entire script — partial review misses cross-cutting issues like cleanup and trap handlers.
- After the review, ask: “rewrite the script applying every critical and warning finding.”
- Run
shellcheckon the rewritten version. The two together catch ~95% of real Bash bugs.
Pair this with
shellcheck(https://www.shellcheck.net/)shfmtfor consistent formattingbatsfor testing
Related prompts
-
Ansible Playbook Generator Prompt
Generate idempotent Ansible playbooks with proper handlers, tags, and check-mode support.
-
Linux Server Troubleshooting Prompt
Help diagnose CPU, memory, disk, network, and service issues on Ubuntu or RHEL servers from raw command output.
-
ShellCheck-Driven Bash Hardening Pass Prompt
Run a legacy Bash script through a ShellCheck-informed hardening review that resolves every warning by category, applies strict-mode and quoting fixes, and produces a safe, production-ready rewrite.
-
Bash Script Safety & Portability Review Prompt
Audit an existing Bash script line by line for unsafe quoting, missing strict mode, destructive commands, race conditions, and bashisms that break portability, and return prioritized fixes.
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.