Agent skill · software engineering · aiskillstore

bash-defensive-patterns

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.

Why this skill is useful

Provides specific defensive programming patterns and error handling techniques for Bash scripts that the AI wouldn't reliably generate on its own.

What it needs

About 6k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.

What this skill does

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 Core Defensive Principles 1. Strict Mode Enable bash strict mode at the start of every script to catch errors early. Key flags: set -E: Inherit ERR trap in functions set -e: Exit on any error (command returns non-zero) set -u: Exit on undefined variable reference set -o pipefail: Pipe fails if any command fails (not just last) 2. Error Trapping and Cleanup Implement proper cleanup on script exit or error. 3. Variable Safety Always quote variables to prevent word splitting and globbing issues. 4. Array Handling Use arrays safely for complex data handling. 5. Conditional Safety Use [[ ]] for Bash-specific features, [ ] for POSIX. Fundamental Patterns Pattern 1: Safe Script Directory Detection Pattern 2: Comprehensive Function Templat Pattern 3: Safe Temporary File Handling Pattern 4: Robust Argument Parsing Pattern 5: Structured Logging Pattern 6: Process Orchestration with Signals Pattern 7: Safe File Operations Pattern 8: Idempotent Script Design Pattern 9: Safe Command Substitution Pattern 10: Dry-Run Support Advanced Defensive Techniques Named Parameters Pattern Dependency Checking 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. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aiskillstore/bash-defensive-patterns--f9d5d2

View the source on GitHub

Browse the @skills marketplace