bash-scripting

majiayu000's avatarfrom majiayu000

Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts. Use when writing, creating, authoring, generating, or developing bash scripts, shell scripts, or automation. Also triggers for learning bash best practices, understanding defensive programming patterns, implementing error handling, ensuring portability, following shellcheck recommendations, or applying production-grade bash standards. Helps with CI/CD scripts, system utilities, deployment automation, and production bash code.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill serves as a specialized expert for developing production-grade, defensive Bash scripts tailored for DevOps automation and CI/CD pipelines. It emphasizes safety, portability, and maintainability by implementing strict error handling, POSIX compliance, and industry-standard tools like ShellCheck and the Bats testing framework. It is designed to transform complex automation tasks into robust, secure, and well-documented shell utilities.

Use Cases

  • Architecting robust CI/CD pipeline scripts with 'strict mode' and advanced error trapping to ensure deployment reliability.
  • Developing portable system utilities and automation tools that function seamlessly across different Linux distributions and macOS environments.
  • Refactoring legacy shell scripts to implement defensive programming patterns, safe variable expansions, and rigorous input validation.
  • Creating comprehensive automated test suites for shell scripts using Bats-core to validate complex logic and edge cases.
  • Implementing secure file operations and process orchestration in production environments to prevent common shell injection and data loss risks.
namebash-scripting
descriptionMaster of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts. Use when writing, creating, authoring, generating, or developing bash scripts, shell scripts, or automation. Also triggers for learning bash best practices, understanding defensive programming patterns, implementing error handling, ensuring portability, following shellcheck recommendations, or applying production-grade bash standards. Helps with CI/CD scripts, system utilities, deployment automation, and production bash code.
allowed-tools[Read, Edit, Write, Grep, Glob, Bash]

Reference Files

Deep-dive guides for specific topics:


Bash Scripting

Master guide for defensive Bash scripting following production-grade best practices. This skill provides comprehensive patterns, standards, and techniques for writing safe, portable, and maintainable shell scripts for automation, CI/CD pipelines, and system utilities.

Use this skill when writing new bash scripts or improving existing ones to follow defensive programming principles.

Focus Areas

  • Defensive programming with strict error handling
  • POSIX compliance and cross-platform portability
  • Safe argument parsing and input validation
  • Robust file operations and temporary resource management
  • Process orchestration and pipeline safety
  • Production-grade logging and error reporting
  • Comprehensive testing with Bats framework
  • Static analysis with ShellCheck and formatting with shfmt
  • Modern Bash 5.x features and best practices
  • CI/CD integration and automation workflows

Core Approach

Essential defensive programming patterns (see patterns-and-conventions.md for complete details):

  • Strict mode: Always use set -Eeuo pipefail with error trapping
  • Quote variables: Prevent word splitting and globbing issues
  • Safe iteration: Use proper arrays, avoid for f in $(ls)
  • Conditionals: Use [[ ]] for Bash, [ ] for POSIX
  • Temp files: Create safely with mktemp and cleanup traps
  • Output: Prefer printf over echo for reliability
  • Input validation: Check required variables with : "${VAR:?message}"
  • Safe operations: End option parsing with --, use rm -rf -- "$dir"
  • NUL-safe patterns: Use find -print0 | while IFS= read -r -d '' for filenames
  • Logging: Implement structured logging with configurable verbosity
  • Idempotency: Design scripts to be repeatable and support dry-run modes

Quality Checklist

  • Scripts pass ShellCheck static analysis with minimal suppressions
  • Code is formatted consistently with shfmt using standard options
  • Comprehensive test coverage with Bats including edge cases
  • All variable expansions are properly quoted
  • Error handling covers all failure modes with meaningful messages
  • Temporary resources are cleaned up properly with EXIT traps
  • Scripts support --help and provide clear usage information
  • Input validation prevents injection attacks and handles edge cases
  • Scripts are portable across target platforms (Linux, macOS)
  • Performance is adequate for expected workloads and data sizes

Output

Production-ready deliverables:

  • Bash scripts with defensive programming practices
  • Test suites using bats-core or shellspec with TAP output
  • CI/CD pipeline configurations for automated testing
  • Documentation (shdoc markdown, shellman man pages)
  • Static analysis configuration (.shellcheckrc, .shfmt.toml)
  • Security review with SAST and secrets scanning
  • Structured logging and observability

Where to Find What