mcpbeat

Bash Defensive Patterns

wshobson/bash-defensive-patterns

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.

3k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
38452
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/wshobson/agents --skill bash-defensive-patterns

The instruction itself

4 sections, as written by the author

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

  • Always use strict mode - set -Eeuo pipefail
  • Quote all variables - "$variable" prevents word splitting
  • Use [[]] conditionals - More robust than [ ]
  • Implement error trapping - Catch and handle errors gracefully
  • Validate all inputs - Check file existence, permissions, formats
  • Use functions for reusability - Prefix with meaningful names
  • Implement structured logging - Include timestamps and levels
  • Support dry-run mode - Allow users to preview changes
  • 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

How to use it

Copy the folder

Take wshobson/bash-defensive-patterns from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.