--- name: bash description: >- Guide for writing production-quality bash scripts following modern idiomatic practices. Enforces set -euo pipefail, [[ ]] conditionals, ${var} syntax, ShellCheck compliance. Triggers on "bash script", "shell script", ".sh file", "write a script", "automation script", "bash function", "shellcheck", "bash template", "pre-commit hook", "deploy script", "build script", "install script", "setup script", "bash error handling", "bash arrays", "bash loop", "bash conditional", "parse arguments", "getopts", "bash logging", "#!/bin/bash", "source script", "dot script", "shell function", "edit script", "update script", "modify script", "change script", "edit .sh", "update .sh", "modify .sh", "statusline.sh", "hook script". PROACTIVE: MUST invoke BEFORE editing/writing ANY .sh file or pre-commit hook. allowed-tools: Read, Write, Edit, Bash, Glob, Grep --- # ABOUTME: Bash scripting skill for production-quality scripts with Bash 4.x+ # ABOUTME: Emphasizes safety, readability, maintainability, and mandatory ShellCheck compliance # Bash Scripting Skill **Target**: Bash 4.0+ with mandatory ShellCheck compliance. **Detailed patterns**: See `references/script-template.md` and `references/advanced-patterns.md` --- ## 🛑 FILE OPERATION CHECKPOINT (BLOCKING) **Before EVERY `Write` or `Edit` tool call on a `.sh` file or shell script:** ``` ╔══════════════════════════════════════════════════════════════════╗ ║ 🛑 STOP - BASH SKILL CHECK ║ ║ ║ ║ You are about to modify a shell script. ║ ║ ║ ║ QUESTION: Is /bash skill currently active? ║ ║ ║ ║ If YES → Proceed with the edit ║ ║ If NO → STOP! Invoke /bash FIRST, then edit ║ ║ ║ ║ This check applies to: ║ ║ ✗ Write tool with file_path ending in .sh ║ ║ ✗ Edit tool with file_path ending in .sh ║ ║ ✗ Files named "pre-commit", "post-commit", etc. (git hooks) ║ ║ ✗ ANY shell script, regardless of conversation topic ║ ║ ║ ║ Examples that REQUIRE this skill: ║ ║ - "update the statusline" (edits statusline.sh) ║ ║ - "add a feature to the hook" (edits pre-commit) ║ ║ - "fix the deploy script" (edits deploy.sh) ║ ╚══════════════════════════════════════════════════════════════════╝ ``` **Why this matters:** Shell scripts without proper safety headers (`set -euo pipefail`) can fail silently or cause data corruption. The skill ensures ShellCheck compliance. --- ## Quick Reference | Pattern | Use | Avoid | |---------|-----|-------| | Conditionals | `[[ "${var}" == "x" ]]` | `[ $var == "x" ]` | | Variables | `"${var}"` (quoted) | `$var` (unquoted) | | Command sub | `$(command)` | `` `command` `` | | Arithmetic | `(( count++ ))` | `let count++` | | Error handling | `set -euo pipefail` | No safety flags | --- ## When to Use Bash **USE for** (< 200 lines): - Quick automation tasks - Build/deployment scripts - System administration - Glue code between tools **DON'T USE for**: - Complex business logic - Robust error handling with recovery - Long-running services - Code requiring unit testing If script exceeds ~200 lines, consider Python or Go. --- ## 🔄 RESUMED SESSION CHECKPOINT ``` ┌─────────────────────────────────────────────────────────────┐ │ SESSION RESUMED - BASH SKILL VERIFICATION │ │ │ │ Before continuing: │ │ 1. Does script have set -euo pipefail? │ │ 2. Are all variables quoted: "${var}"? │ │ 3. Using [[ ]] conditionals (not [ ])? │ │ 4. Run: shellcheck