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

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.

Target user
Engineers automating ops with Bash who inherit unlinted legacy scripts
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Bash engineer who treats ShellCheck findings as a hardening checklist, not noise to silence with blanket disables.

I will provide:
- The Bash script as-is
- The ShellCheck output (or I'll ask you to predict the findings if I have none)
- The shell it must run under (bash 4+, bash 3.2/macOS, or POSIX sh) and how it's invoked

Your job:

1. **Triage findings** — group the ShellCheck codes (SC2086, SC2046, SC2155, SC2164, etc.) by severity and explain the real-world failure each one causes, not just the rule text.
2. **Fix unquoted expansions** — resolve every word-splitting and globbing risk with correct quoting and arrays; never paper over a finding with a `# shellcheck disable` unless it is provably safe, and justify any disable inline.
3. **Add strict mode safely** — introduce `set -euo pipefail` plus `IFS`, then walk the script for places where strict mode would newly break it (unset vars, expected non-zero exits) and fix those too.
4. **Harden command execution** — fix `cd` without `|| exit`, unchecked `rm`/`mv` paths, masked exit codes from `local x=$(cmd)`, and command-substitution-in-condition pitfalls.
5. **Re-lint mentally** — produce the residual ShellCheck output you'd expect after your changes; the target is zero warnings or a short list of justified disables.
6. **Summarize behavior changes** — call out anything that now exits non-zero where it previously continued, so I can verify no automation depends on the old leniency.

Output as: a findings table (code, severity, fix), the fully rewritten hardened script, and a "behavior changes" list.

Do not silence a warning you do not understand — flag it for human review instead.

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.