Bash Defensive Patterns
SkillAI & modelsHelps your agent write reliable shell scripts with strict error handling, input checks, and safe patterns.
Use Bash Defensive Patterns in Claude, ChatGPT or Ahel Desktop
Free. Sign in, add Bash Defensive Patterns and connect your AI. About a minute.
Also: Claude Code · Cursor · Codex
Then ask your AI: use the Bash Defensive Patterns skill
Details
Instructions available. Your AI can read the instructions. Execution depends on the setup they require.
Account requirements not reviewed. Check the skill instructions before use; ahel provides instructions and does not run this skill.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
About this skill
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.
What this skill tells your AI
The instructions your AI receives, as published by wshobson/agents in plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md and read by ahel’s review.
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 thanwhichfor checking executables - Prefer printf over echo - More predictable across systems
Signals
- GitHub stars
- 40k
- Forks
- 4k
- Last commit
- Sep 2026
Others that do the same job
Advanced
- Item type
- skill
- Key
bash-defensive-patterns-wshobson- Source
- github.com/wshobson/agents
Related picks
Skill · countbot-ai
The pick for Croncron-packs
Skill · profbernardoj
The pick for Crongithub-actions
Skill · tddworks
The pick for GitHub Actionsgithub-actions-docs
Skill · devantler-tech
The pick for GitHub Actionsskill-creator
Skill · anthropics
More in AI & modelswayfinder
Skill · mattpocock
More in AI & models