Master defensive Bash programming techniques for production-grade scripts.
SkillScore95Maintained
Automatic
◆DevOps & SRE pack
Last verified 8/7/2026
What it changes
Passed 21 of 22 test cases with the skill, and 18 of 22 without it.
Without skill82%
With skill95%
Checks it passed that the model alone missed
Temporary files are created using `mktemp`.
Output formatting uses `printf` instead of `echo`.
The shell script includes strict mode `set -Eeuo pipefail`.
and 4 more in the full report
4 fixed17 passed either way0 still failing1 broke
Pass-rate lift
+14 pp
Tokens
+34%
Agent turns
0%
Response time
+10%
Model gemini-3.6-flashMeasured 8/7/2026v121 of 22 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 4 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 4
Prompt
Write a short bash utility script `cleanup_logs.sh` that deletes `.log` files older than 30 days in `/var/log/app`. Use standard shell error handling settings so pipe failures and unset variables stop execution immediately.
What was checked, without and with the skill
Checked
Without skill
With skill
The shell script enables strict mode using `set -Eeuo pipefail`.
Missed
Passed
case-07 · gemini-3.6-flash · 8/7/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md35 lines2 files
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
Design for idempotency - Scripts should be safe to rerun
Document requirements - List dependencies and minimum versions
Test error paths - Ensure error handling works correctly
Use command -v - Safer than which for checking executables
Prefer printf over echo - More predictable across systems