bash-defensive-patterns
bmcszk/agent-skills/skills/bash-defensive-patterns/SKILL.md
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.
Skill1 starsChanged 10 days ago
What's in it
- Bash Defensive Patterns
- When to Use This Skill
- Detailed patterns and worked examples
- Best Practices Summary
--- 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. --- # 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
More agent context in bmcszk/agent-skills
30 other files this repository gives its agents.
Skill
- arch-linux-cachyosskills/arch-linux-cachyos/SKILL.md
- arch-linux-triageskills/arch-linux-triage/SKILL.md
- bash-linuxskills/bash-linux/SKILL.md
- bash-scriptingskills/bash-scripting/SKILL.md
- beansskills/beans/SKILL.md
- context7skills/context7/SKILL.md
- docker-compose-setupskills/docker-compose-setup/SKILL.md
- audioskills/ebiten/audio/SKILL.md
- deploymentskills/ebiten/deployment/SKILL.md
- ecsskills/ebiten/ecs/SKILL.md
- game-loopskills/ebiten/game-loop/SKILL.md
- inputskills/ebiten/input/SKILL.md
- physicsskills/ebiten/physics/SKILL.md
- renderingskills/ebiten/rendering/SKILL.md
- resourcesskills/ebiten/resources/SKILL.md
- ebitenskills/ebiten/SKILL.md
- geminiskills/gemini/SKILL.md
- go-browser-testsskills/go-browser-tests/SKILL.md
- go-devskills/go-dev/SKILL.md
- go-fluent-testingskills/go-fluent-testing/SKILL.md
- go-htmx-frontendskills/go-htmx-frontend/SKILL.md
- go-setupskills/go-setup/SKILL.md
- interactive-browser-testingskills/interactive-browser-testing/SKILL.md
- keep-on-goingskills/keep-on-going/SKILL.md
- mcpcskills/mcpc/SKILL.md
- minimaxskills/minimax/SKILL.md
- pixellabskills/pixellab/SKILL.md
- playwright-mcpskills/playwright-mcp/SKILL.md
- public-repo-maturityskills/public-repo-maturity/SKILL.md
- searxngskills/searxng/SKILL.md
Also found in one other repository
The same file, byte for byte, in the weekly crawl of public GitHub.
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

