bash-defensive-patterns – Writing & Content skill for AI agents
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.
Install the bash-defensive-patterns skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/bash-defensive-patterns-03ed7.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /bash-defensive-patterns – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/bash-defensive-patterns-03ed7.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $bash-defensive-patterns – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/bash-defensive-patterns-03ed7.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /bash-defensive-patterns – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/bash-defensive-patterns-03ed7.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /bash-defensive-patterns – then describe the task you want done.
SKILL.md content
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
Related skills
- ai-act-readiness – /compliance-os:ai-act-readiness [system] — EU AI Act 6-question forcing interrogation…
- internal-comms – A set of resources to help me write all kinds of internal communications, using the…
- ai-blog-intro-writer – AI Blog Intro Writer. Use when working with topic and article angle, or article draft.
- ai-content-detector – AI Content Detector. Use when working with text to review.
- ai-content-improver – AI Content Improver. Use when working with draft text.
- baoyu-article-illustrator – Article illustrations: type × style × palette consistency.
- ai-content-outline-generator – AI Content Outline Generator. Use when working with topic or reader question.
- ai-faq-creator – AI FAQ Creator. Use when working with source content or topic.