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.
Use this skill when
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
Do not use this skill when
You need a single ad-hoc shell command, not a script
The target environment requires strict POSIX sh only
The task is unrelated to shell scripting or automation
Instructions
Confirm the target shell, OS, and execution environment.
Enable strict mode and safe defaults from the start.
Validate inputs, quote variables, and handle files safely.
Add logging, error traps, and basic tests.
Safety
Avoid destructive commands without confirmation or dry-run flags.
Do not run scripts as root unless strictly required.
Refer to resources/implementation-playbook.md for detailed patterns, checklists, and templates.
Resources
resources/implementation-playbook.md for detailed patterns, checklists, and templates.
1---2name: bash-defensive-patterns3description: Bash Defensive Patterns4---5# Bash Defensive Patterns67Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.89## Use this skill when1011- Writing production automation scripts12- Building CI/CD pipeline scripts13- Creating system administration utilities14- Developing error-resilient deployment automation15- Writing scripts that must handle edge cases safely16- Building maintainable shell script libraries17- Implementing comprehensive logging and monitoring18- Creating scripts that must work across different platforms1920## Do not use this skill when2122- You need a single ad-hoc shell command, not a script23- The target environment requires strict POSIX sh only24- The task is unrelated to shell scripting or automation2526## Instructions27281. Confirm the target shell, OS, and execution environment.292. Enable strict mode and safe defaults from the start.303. Validate inputs, quote variables, and handle files safely.314. Add logging, error traps, and basic tests.3233## Safety3435- Avoid destructive commands without confirmation or dry-run flags.36- Do not run scripts as root unless strictly required.3738Refer to `resources/implementation-playbook.md` for detailed patterns, checklists, and templates.3940## Resources4142- `resources/implementation-playbook.md` for detailed patterns, checklists, and templates.
Run npx skillmds@latest add comeonoliver/bash-defensive-patterns in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Bash Defensive Patterns It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.