bash-defensive-patterns
Implements error handling and safety patterns to make Bash scripts production-ready.
Install
mkdir -p .claude/skills/bash-defensive-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1724" && unzip -o skill.zip -d .claude/skills/bash-defensive-patterns && rm skill.zipInstalls to .claude/skills/bash-defensive-patterns
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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.Key capabilities
- →Implement strict mode error handling
- →Validate input and file permissions
- →Create structured logs with timestamps
- →Support dry-run execution modes
- →Design idempotent scripts
How it works
It applies defensive programming patterns like strict mode, variable quoting, and error trapping to ensure scripts handle edge cases and failures gracefully.
Inputs & outputs
When to use bash-defensive-patterns
- →Writing CI/CD pipeline scripts
- →Creating robust system administration utilities
- →Developing error-resilient deployment automation
- →Implementing input validation for CLI tools
About this skill
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 thanwhichfor checking executables - Prefer printf over echo - More predictable across systems
When not to use it
- →Simple one-off commands that do not require fault tolerance
Limitations
- →Requires adherence to specific coding patterns for effectiveness
How it compares
It enforces structured, production-grade patterns instead of relying on standard, error-prone shell scripting practices.
Compared to similar skills
bash-defensive-patterns side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| bash-defensive-patterns (this skill) | 3 | 2mo | No flags | Intermediate |
| bazel-build-optimization | 14 | 2mo | No flags | Advanced |
| wolf-scripts-core | 5 | 9mo | Review | Intermediate |
| cicd-automation-workflow-automate | 3 | 4mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by wshobson
View all by wshobson →You might also like
bazel-build-optimization
wshobson
Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
wolf-scripts-core
Nice-Wolf-Studio
Core automation scripts for archetype selection, evidence validation, quality scoring, and safe bash execution
cicd-automation-workflow-automate
sickn33
You are a workflow automation expert specializing in creating efficient CI/CD pipelines, GitHub Actions workflows, and automated development processes. Design automation that reduces manual work, improves consistency, and accelerates delivery while maintaining quality and security.
managing-devops-pipeline
TencentBlueKing
管理蓝盾流水线的构建操作,包括查询构建历史、获取启动参数、查看构建状态、启动构建。当用户提及流水线、构建、部署、CI/CD、蓝盾或需要触发构建任务时使用。
monitor-ci
nrwl
Monitor Nx Cloud CI pipeline and handle self-healing fixes. USE WHEN user says "monitor ci", "watch ci", "ci monitor", wants to track CI status, or needs help with self-healing CI fixes
GitHub Actions CI Builder
agentskillexchange
Generate and manage GitHub Actions workflow YAML files using the GitHub Actions REST API and workflow_dispatch events. Supports matrix builds, reusable workflows, and composite actions.