Skip to content

Bash Defensive Patterns

Teaches the agent to write safer, more fault-tolerant Bash scripts for production use.

Repository
wshobson/agents
Stars
42,095
Licence
MIT
Files
2 files

What it does

When installed, this skill gives the agent a set of best practices for writing shell scripts that fail safely and behave predictably. Examples include strict error handling, quoting variables correctly, cleaning up temporary files, adding logging, and supporting a dry-run preview before changes are made. The agent applies these conventions when it writes Bash code, and can consult a supporting reference document with worked examples.

Great for

  • Developers writing deployment or CI/CD pipeline scripts in Bash
  • Sysadmins building reliable automation or maintenance utilities
  • Anyone who wants shell scripts that stop on errors instead of continuing silently

Skip it if

  • Scripts that must run on non-Bash shells or Windows, since the patterns assume Bash features (the skill itself notes cross-platform concerns only briefly) and the reason is that syntax differs between shells
  • Quick one-off commands where strict mode and extensive logging add unnecessary complexity
  • Blindly trusting the output as tested code: the skill is guidance, not a verified test suite, so generated scripts still need review before running on production systems

Try asking

  • “Write a Bash script that deploys our app to staging with error trapping and a dry-run flag”
  • “Review this existing shell script and suggest defensive improvements like quoting and strict mode”
  • “Create a cleanup utility that uses mktemp and removes temporary files on exit”
  • “Build a logging helper for our CI pipeline shell scripts with timestamps and log levels”
Step-by-step guide: how to use Bash Defensive PatternsInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 2 original files, the MIT licence and an attribution note.

    bash-defensive-patterns.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip bash-defensive-patterns.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip bash-defensive-patterns.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Name the target environment (Bash version, OS, CI system) so the agent picks compatible syntax.
  • Ask for the dry-run mode and test cases explicitly, since the skill recommends them but you should confirm they are included.
  • Always read generated scripts before running them, especially ones that delete files or change system settings.

What's inside

  • references/details.md
  • SKILL.md

Redistributed unmodified from wshobson/agents under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.