BA

bash-defensive-patterns

Implements error handling and safety patterns to make Bash scripts production-ready.

Install

mkdir -p .claude/skills/bash-defensive-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1724" && unzip -o skill.zip -d .claude/skills/bash-defensive-patterns && rm skill.zip

Installs to .claude/skills/bash-defensive-patterns

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.
188 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Implement strict mode error handling
  • Validate input and file permissions
  • Create structured logs with timestamps
  • Support dry-run execution modes
  • Design idempotent scripts

How it works

It applies defensive programming patterns like strict mode, variable quoting, and error trapping to ensure scripts handle edge cases and failures gracefully.

Inputs & outputs

You give it
Bash script logic
You get back
Fault-tolerant, production-ready shell script

When to use bash-defensive-patterns

  • Writing CI/CD pipeline scripts
  • Creating robust system administration utilities
  • Developing error-resilient deployment automation
  • Implementing input validation for CLI tools

About this skill

Bash Defensive Patterns

Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.

When to Use This Skill

  • Writing production automation scripts
  • Building CI/CD pipeline scripts
  • Creating system administration utilities
  • Developing error-resilient deployment automation
  • Writing scripts that must handle edge cases safely
  • Building maintainable shell script libraries
  • Implementing comprehensive logging and monitoring
  • Creating scripts that must work across different platforms

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices Summary

  1. Always use strict mode - set -Eeuo pipefail
  2. Quote all variables - "$variable" prevents word splitting
  3. Use [[]] conditionals - More robust than [ ]
  4. Implement error trapping - Catch and handle errors gracefully
  5. Validate all inputs - Check file existence, permissions, formats
  6. Use functions for reusability - Prefix with meaningful names
  7. Implement structured logging - Include timestamps and levels
  8. Support dry-run mode - Allow users to preview changes
  9. Handle temporary files safely - Use mktemp, cleanup with trap
  10. Design for idempotency - Scripts should be safe to rerun
  11. Document requirements - List dependencies and minimum versions
  12. Test error paths - Ensure error handling works correctly
  13. Use command -v - Safer than which for checking executables
  14. Prefer printf over echo - More predictable across systems

When not to use it

  • Simple one-off commands that do not require fault tolerance

Limitations

  • Requires adherence to specific coding patterns for effectiveness

How it compares

It enforces structured, production-grade patterns instead of relying on standard, error-prone shell scripting practices.

Compared to similar skills

bash-defensive-patterns side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
bash-defensive-patterns (this skill)32moNo flagsIntermediate
bazel-build-optimization142moNo flagsAdvanced
wolf-scripts-core59moReviewIntermediate
cicd-automation-workflow-automate34moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by wshobson

View all by wshobson

Search skills

Search the agent skills registry