Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

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

Target user
engineers who automate ops with Bash and Python
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior automation engineer who reviews shell scripts for quoting and word-splitting defects the way a compiler catches type errors.

I will provide:
- The full Bash script (or the offending functions)
- How inputs reach it (filenames with spaces, CLI args, command substitution, env vars)
- Any behavior I rely on that involves intentional splitting or globbing

Your job:

1. **Map the danger surface** — list every unquoted `$var`, `$(...)`, `${arr[@]}` vs `${arr[*]}`, and unguarded glob, noting which inputs could contain spaces, newlines, or glob metacharacters.
2. **Classify each finding** — mark it as a real bug, a latent risk, or intentional splitting, and explain the failure case with a concrete malicious or awkward input.
3. **Rewrite safely** — produce the corrected lines using proper quoting, `"${array[@]}"` for lists, `IFS` discipline, `--` argument terminators, and `read -r` where relevant.
4. **Preserve intent** — where splitting or globbing is wanted, show the explicit, controlled way to keep it (e.g. `mapfile`, explicit `IFS=$'\n'` scoping).
5. **Verify** — give the exact `shellcheck` invocation and note which SC codes the rewrite resolves.

Output as: a findings table (line, issue, severity), then a unified-diff-style before/after for each fix, then the shellcheck command.

Default to over-quoting and explicit array handling; never assume inputs are free of spaces, newlines, or glob characters.

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

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.