Bash Defensive Patterns
Unverified●29/40Claude Code◐PartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
Cursor◐PartialPlain prose you can paste in — but no Cursor rules file
Codex◐PartialPlain prose you can paste in — but no AGENTS.md
Gemini CLI◐PartialPlain prose you can paste in
Copilot◐PartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add bash-defensive-patternsWho is stuck, and on what
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.
The whole source
Frontmatter — 2 properties
| name | bash-defensive-patterns |
|---|---|
| description | 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. |
| 1 | --- |
| 2 | name: bash-defensive-patterns |
| 3 | description: 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. |
| 4 | ---A5 — No allowed-tools declared — no way to tell what this skill may touch |
| 5 | |
| 6 | # Bash Defensive Patterns |
| 7 | |
| 8 | 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. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | - Writing production automation scripts |
| 13 | - Building CI/CD pipeline scripts |
| 14 | - Creating system administration utilities |
| 15 | - Developing error-resilient deployment automation |
| 16 | - Writing scripts that must handle edge cases safely |
| 17 | - Building maintainable shell script libraries |
| 18 | - Implementing comprehensive logging and monitoring |
| 19 | - Creating scripts that must work across different platforms |
| 20 | |
| 21 | ## Detailed patterns and worked examples |
| 22 | |
| 23 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 24 | |
| 25 | ## Best Practices Summary |
| 26 | |
| 27 | 1. **Always use strict mode** - `set -Eeuo pipefail` |
| 28 | 2. **Quote all variables** - `"$variable"` prevents word splitting |
| 29 | 3. **Use [[]] conditionals** - More robust than [ ] |
| 30 | 4. **Implement error trapping** - Catch and handle errors gracefully |
| 31 | 5. **Validate all inputs** - Check file existence, permissions, formats |
| 32 | 6. **Use functions for reusability** - Prefix with meaningful names |
| 33 | 7. **Implement structured logging** - Include timestamps and levels |
| 34 | 8. **Support dry-run mode** - Allow users to preview changes |
| 35 | 9. **Handle temporary files safely** - Use mktemp, cleanup with trap |
| 36 | 10. **Design for idempotency** - Scripts should be safe to rerun |
| 37 | 11. **Document requirements** - List dependencies and minimum versions |
| 38 | 12. **Test error paths** - Ensure error handling works correctly |
| 39 | 13. **Use `command -v`** - Safer than `which` for checking executables |
| 40 | 14. **Prefer printf over echo** - More predictable across systems |
| 41 |
Reviews
Installed this one?Write the first review and take the Trailblazer badge.
Alternatives
Subagent Driven DevelopmentUse when executing implementation plans with independent tasks in the current session◐◐◐◐◐●36/40Python Code Style & DocumentationPython code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.◐····●35/40Competitor Price Analysis 💲Competitor pricing strategy analysis and market positioning. Price mapping, pricing gaps identification, elasticity signals evaluation, and strategic pricing optimization. Use when the user asks about competitor pricing, price analysis, pricing strategy, or co◐····●34/40Competitor Price Tracker 📊Set up competitor price tracking and monitoring workflows. Track price changes, detect promotions, analyze pricing patterns, and get alerts for competitive price movements.◐····●34/40