Skills · Coding

Bash Defensive Patterns

Unverified29/40

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.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add bash-defensive-patterns

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

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.

The whole source

No sign-in, no blur, nothing truncated
bash-defensive-patterns/SKILL.md41 lines1.9 KBRawView on GitHub
Frontmatter — 2 properties
namebash-defensive-patterns
descriptionMaster 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.
1---
2name: bash-defensive-patterns
3description: 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.
4---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# Bash Defensive Patterns
7 
8Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.
9 
10## When to Use This Skill
11 
12- Writing production automation scripts
13- Building CI/CD pipeline scripts
14- Creating system administration utilities
15- Developing error-resilient deployment automation
16- Writing scripts that must handle edge cases safely
17- Building maintainable shell script libraries
18- Implementing comprehensive logging and monitoring
19- Creating scripts that must work across different platforms
20 
21## Detailed patterns and worked examples
22 
23Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
24 
25## Best Practices Summary
26 
271. **Always use strict mode** - `set -Eeuo pipefail`
282. **Quote all variables** - `"$variable"` prevents word splitting
293. **Use [[]] conditionals** - More robust than [ ]
304. **Implement error trapping** - Catch and handle errors gracefully
315. **Validate all inputs** - Check file existence, permissions, formats
326. **Use functions for reusability** - Prefix with meaningful names
337. **Implement structured logging** - Include timestamps and levels
348. **Support dry-run mode** - Allow users to preview changes
359. **Handle temporary files safely** - Use mktemp, cleanup with trap
3610. **Design for idempotency** - Scripts should be safe to rerun
3711. **Document requirements** - List dependencies and minimum versions
3812. **Test error paths** - Ensure error handling works correctly
3913. **Use `command -v`** - Safer than `which` for checking executables
4014. **Prefer printf over echo** - More predictable across systems
41 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Coding