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.
Collected from public GitHub. Every version is saved exactly as it was and never changes. Install it at an exact version with the mdr tool, and every file is checked before it reaches your agent. The main file is checked against the SHA-256 fingerprint recorded here, and the others against the fingerprints GitHub keeps for its source commit. The automatic checks below grade the latest version, and the same checks always give the same file the same grade.
What the file says
# 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
1. **Always use strict mode** - `set -Eeuo pipefail`
2. **Quote all variables** - `"$variable"` prevents word splitting
3. **Use [[]] conditionals** - More robust than [ ]
4. **Implement error trapping** - Catch and handle errors gracefully
5. **Validate all inputs** - Check file existence, permissions, formats
…
The line at the top of this page pins the label git:20260612.b83c59d, which is what most people want. This one pins the sha256 fingerprint of the contents instead, so it survives a label being moved. Either way the exact version is written to mdr.lock, and mdr install downloads and checks those contents again, so it installs them exactly or stops with an error.
GET https://markdownregistry.com/api/v1/artifacts/art_db764ozzcjeqw7hd
GET https://markdownregistry.com/api/v1/resolve?ref=martineserios/thebrana/bash-defensive-patterns
GET https://markdownregistry.com/api/v1/blob/f82f5c9c7ecf65516e53db01de1cf9a5f0ea08bd736b415f8fa9b3d541fe3b69
Your AI assistant does the legwork. You hear about the deals worth your word. Hand yours the standing instructions at modelranch.com and it joins the network that reads files like this one.
martineserios/thebrana · .agents/skills/cold-start-problem/SKILL.md · Start and scale networked products using Andrew Chen''s "The Cold Start Problem" framework for network effects. Use…
martineserios/thebrana · .agents/skills/critical-thinking-logical-reasoning/SKILL.md · Critical thinking and logical reasoning analysis skills for when you are explicitly asked to critically analyse written…
martineserios/thebrana · .agents/skills/decision-matrix/SKILL.md · Compares multiple named alternatives against weighted criteria to produce transparent, defensible choices with explicit…
martineserios/thebrana · .agents/skills/domain-driven-design/SKILL.md · DDD tactical patterns for complex business modeling including entities, value objects, aggregates, domain services…
martineserios/thebrana · .agents/skills/first-principles/SKILL.md · Break down complex problems to their fundamental truths, then reason up from there. Master Aristotle's ancient method…
martineserios/thebrana · .agents/skills/inversion/SKILL.md · "Invert, always invert." Apply Carl Jacobi's mathematical principle and Charlie Munger's investing wisdom to solve…
martineserios/thebrana · .agents/skills/jobs-to-be-done/SKILL.md · Discover what customers truly need by analyzing the "job" they hire your product to do. Use when the user mentions…
martineserios/thebrana · .agents/skills/marketplace-fundamentals/SKILL.md · Help users understand the core mechanics of marketplace businesses, from solving the cold start problem to maintaining…
martineserios/thebrana · .agents/skills/marketplace-liquidity-take-rates/SKILL.md · Help users define precise liquidity metrics, set competitive take rates based on value delivery, and manage the…
martineserios/thebrana · .agents/skills/pre-mortem/SKILL.md · Imagine your project has failed spectacularly—then work backward to identify why. Apply Gary Klein's "prospective…
martineserios/thebrana · .agents/skills/second-order-thinking/SKILL.md · Think beyond immediate consequences to understand the chain reactions of decisions. Master Howard Marks' investment…
martineserios/thebrana · .agents/skills/six-thinking-hats/SKILL.md · Apply Edward de Bono's parallel thinking framework (1985) to make better decisions by examining ideas from six distinct…