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.
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.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
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."
4version: 1.0.0
5author:
6 name: "sickn33 / Antigravity Community"
7 github: sickn33
8tags: [bash, defensive, patterns, development]
9category: development
10platforms: [macos, linux, windows]
11license: MIT
12metadata:
13 hermes:
14 source: https://skillmd.com/skills/nous-hermeshub/bash-defensive-patterns
15 upstream: "antigravity-awesome-skills"
16 risk: "safe"
17 date_added: "2026-02-27"
18 original_author: "Antigravity Community"
19---
20
21# Bash Defensive Patterns
22
23Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.
24
25## Use this skill when
26
27- Writing production automation scripts
28- Building CI/CD pipeline scripts
29- Creating system administration utilities
30- Developing error-resilient deployment automation
31- Writing scripts that must handle edge cases safely
32- Building maintainable shell script libraries
33- Implementing comprehensive logging and monitoring
34- Creating scripts that must work across different platforms
35
36## Do not use this skill when
37
38- You need a single ad-hoc shell command, not a script
39- The target environment requires strict POSIX sh only
40- The task is unrelated to shell scripting or automation
41
42## Instructions
43
441. Confirm the target shell, OS, and execution environment.
452. Enable strict mode and safe defaults from the start.
463. Validate inputs, quote variables, and handle files safely.
474. Add logging, error traps, and basic tests.
48
49## Safety
50
51- Avoid destructive commands without confirmation or dry-run flags.
52- Do not run scripts as root unless strictly required.
53
54Refer to `resources/implementation-playbook.md` for detailed patterns, checklists, and templates.
55
56## Resources
57
58- `resources/implementation-playbook.md` for detailed patterns, checklists, and templates.
59
60## Limitations
61- Use this skill only when the task clearly matches the scope described above.
62- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
63- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.