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.
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
-
Python Regex Extraction and Validation Toolkit Prompt
Build correct, readable, and well-tested regular expressions in Python for parsing logs, validating input, and extracting structured fields — with named groups, verbose mode, and catastrophic-backtracking checks.
-
Bash .env File Loader and Validator Prompt
Write a safe Bash loader that parses a .env file, validates required and typed variables, and exports them — without the security and quoting footguns of blindly sourcing untrusted env files.
-
Bash to POSIX sh Portability Audit Prompt
Audit a Bash script for bashisms and rewrite it as portable POSIX sh so it runs identically under dash, busybox ash, and Alpine containers without a bash binary.
-
Python Pydantic Settings Config Prompt
Replace ad-hoc os.environ access and scattered config parsing with a typed pydantic-settings model — validated env vars, .env loading, nested settings, secrets, and clear startup errors instead of runtime KeyErrors.
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.