bash-patterns

Provide idiomatic Bash scripting patterns for error handling, getopts parsing, and bats-core testing.

1|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/flatrick/mdt --skill bash-patterns-flatrick
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: bash-patterns
Source: https://github.com/flatrick/mdt/tree/main/skills/bash-patterns
Command: npx skills add https://github.com/flatrick/mdt --skill bash-patterns-flatrick

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides best practices and reusable patterns for writing safe, portable, and maintainable Bash/shell scripts, reducing bugs and security vulnerabilities.

Core Features & Use Cases

  • Script Hardening: Implement safety headers (set -euo pipefail) and safe temporary file handling (mktemp, trap).
  • Argument Parsing: Use getopts for robust command-line argument handling.
  • Testing: Integrate with bats-core for automated testing of shell scripts.
  • Cross-Platform Compatibility: Address differences between macOS (BSD) and Linux (GNU) tools.
  • Use Case: When developing a new deployment script for a CI/CD pipeline, use these patterns to ensure it's secure, handles errors gracefully, and works across different environments.

Quick Start

Use the bash-patterns skill to generate a new, robust bash script template.

Frequently Asked Questions about bash-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make bash scripts safe and prevent errors from breaking my automation?▼

Make bash scripts safe by implementing script hardening headers like `set -euo pipefail`. This ensures robust automation by stopping execution immediately when errors occur or unset variables are encountered.

How do I handle command-line arguments in shell scripts using getopts?▼

Handle command-line arguments in shell scripts using `getopts` for robust parsing. This built-in mechanism safely processes flags and options, preventing argument handling errors in your automation workflows.

How do I test bash scripts with bats-core?▼

Test bash scripts with bats-core by integrating its automated testing framework into your development workflow. This provides reliable validation of shell script logic and ensures your patterns function correctly.

How do I write shell scripts that work on both macOS and Linux?▼

Write cross-platform shell scripts by addressing differences between macOS (BSD) and Linux (GNU) command-line tools. This ensures your automation scripts run reliably across different operating system environments.

What is the best way to handle temporary files securely in shell scripting?▼

Handle temporary files securely in shell scripting by using `mktemp` to generate unique file paths and `trap` to guarantee cleanup. This prevents security vulnerabilities and removes leftover files.

Why should I use safe scripting patterns for CI/CD pipeline deployment scripts?▼

Use safe scripting patterns for CI/CD pipeline deployment scripts to ensure they are secure, handle errors gracefully, and work across different environments. This reduces bugs and security vulnerabilities in automation.