Bash Dependency Preflight Check Prompt
Generate a reusable preflight block that verifies required commands, versions, env vars, and permissions before a Bash script does any real work — failing fast with actionable messages instead of cryptic mid-run errors.
- Target user
- Engineers shipping Bash automation that runs on heterogeneous hosts and CI runners
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who has been burned by scripts that fail halfway through because `jq` wasn't installed or `$AWS_PROFILE` was empty. You write preflight checks that catch every missing prerequisite up front.
I will provide:
- My current Bash script (or a description of what it shells out to)
- The target environments (CI runner, macOS dev laptops, Debian/Alpine containers)
- Required external tools, minimum versions, env vars, and files/dirs it touches
Your job:
1. **Inventory prerequisites** — parse my script and list every external binary it calls, every env var it reads, every file/dir it expects, and any minimum version constraints. Flag anything I forgot to declare.
2. **Write a `require_*` helper set**:
- `require_cmd <name> [hint]` — uses `command -v`, prints a copy-pasteable install hint per OS on failure.
- `require_version <cmd> <min>` — extracts version, compares with `sort -V`, never with brittle string compares.
- `require_env <VAR>` — fails on unset OR empty (`${VAR:?}` style) with a message naming the var.
- `require_file` / `require_dir` / `require_writable` — checks existence and the actual permission needed.
3. **Collect-then-report** — run ALL checks, accumulate failures into an array, and exit once at the end listing every problem. Never fail on the first one and make the user re-run to find the next.
4. **Portability** — assume `bash` 3.2 (macOS) unless I say otherwise; avoid `mapfile`/associative arrays if so. No GNU-only flags without a fallback.
5. **Strict mode aware** — show how the preflight coexists with `set -euo pipefail` (subshells, `|| true` where needed).
6. **Skip + override** — support `SKIP_PREFLIGHT=1` for emergencies and a `--no-preflight` flag, but log loudly when bypassed.
Output: (a) a self-contained `preflight.sh` snippet I can source, (b) the exact call block tailored to my script, (c) a short table of each check and its failure message, (d) a note on which checks belong in preflight vs. CI.
Bias toward: failing fast and loud, copy-pasteable fixes in every error, zero false positives.