bash-master
Skill275 starsChanged 35 days agoMITView on GitHub
Expert bash/shell scripting across environments where Bash is available (Linux, macOS, Git Bash on Windows, WSL, containers). This is a Bash-focused skill - it does not provide PowerShell parity; on Windows the target is the Bash interpreter (Git Bash / WSL), not native PowerShell. PROACTIVELY activate for: (1) ANY bash/shell script task, (2) System automation, (3) DevOps/CI/CD scripts, (4) Build/deployment automation, (5) Script review/debugging, (6) Converting commands to scripts. Provides: Google Shell Style Guide compliance, ShellCheck validation, Bash portability across Linux/macOS/WSL/Git Bash/containers, POSIX compliance, security hardening, error handling, performance optimization, testing with BATS, and production-ready patterns. Ensures professional-grade, secure, portable Bash scripts every time.
In this repository3 other files it gives its agents.
- devopsSkill
- docker-developmentSkill
- release-pr-notesSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 63
Every script should open with the safety preamble:
- Very specific: line 99
Run shellcheck on every script.
- Very specific: line 174
Always check exit codes (if !
- Very specific: line 176
Use getopts or a case-based argument parser.
- Distinctive: line 177
Use a leveled logger that writes to stderr.
- Distinctive: line 191
Read that reference any time you need the canonical code template for one of those topics.
- Very specific: line 212
Run on every target platform (Linux/macOS/WSL/Git Bash/container) where it claims support
- Very specific: line 236
Read the rule explanation (shellcheck -W SC2086).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Bash Scripting Mastery
Scope and platform contract
This skill targets Bash itself, wherever Bash runs - Linux, macOS, WSL, Git Bash / MSYS2 on Windows, and Bash-based container images. It does not cover native PowerShell: a PowerShell script is a different language and should use powershell-master. On Windows, bash-master assumes the user is running Bash inside Git Bash, WSL, or a similar Bash environment, and addresses the MSYS path-translation quirks that result.
Repository conventions
Project-level conventions (Windows backslashes in tool calls, documentation discipline, etc.) live in the agent body and the windows-path-master plugin. This skill focuses on Bash content; do not duplicate that boilerplate here.
Quick reference
#!/usr/bin/env bash
set -euo pipefail # Exit on error, undefined vars, pipe failures
IFS=$'\n\t' # Safe word splitting
# Run shellcheck your_script.sh before deployment.
# Test on every target platform before production.Bash-portability quick check:
# Linux/macOS: Full bash features
# Git Bash (Windows): Most features, some system calls missing (no systemd, /proc differs)
# WSL: Effectively Linux; /mnt/c for Windows filesystem
# Containers: Depends on base image - alpine ships /bin/sh, not bash
# POSIX mode: Use /bin/sh and avoid bashismsWhen to use this skill
Always activate for:
- Writing or modifying any bash/shell script
- Reviewing or refactoring existing scripts
- Debugging shell script failures
- DevOps automation, CI/CD pipelines, system administration
- Cross-environment Bash portability (Linux <-> macOS <-> WSL <-> Git Bash <-> container)
Do not use this skill for:
- PowerShell scripts - use
powershell-master - Batch (
.cmd/.bat) scripting - Generic command help unrelated to scripting
Core principles
1. Safety first
Every script should open with the safety preamble:
#!/usr/bin/env bash
set -e # Exit on any error
set -u # Exit on undefined variable
set -o pipefail # Catch failures mid-pipeline
set -E # Inherit ERR trap into functions
IFS=$'\n\t' # Avoid word splitting on spaces
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"2. POSIX vs Bash
Need to run on any UNIX sh | #!/bin/sh, no [[ ]], no arrays, no process substitution |
| Modern Linux/macOS with Bash | #!/usr/bin/env bash, prefer [[ ]], arrays, regex |
| Alpine/minimal containers | Either install bash explicitly or write POSIX-compliant sh |
3. Quoting
# Always quote expansions
process "$file_path" # correct
process $file_path # word-splitting bug
# Arrays
files=("file 1.txt" "file 2.txt")
process "${files[@]}" # each element kept separate
process "${files[*]}" # joined as one string - usually wrong4. ShellCheck
Run shellcheck on every script. Only disable warnings with a justification comment: # shellcheck disable=SC2086 reason: intentional word splitting.
See references/best_practices.md for the full quoting/style table and references/patterns_antipatterns.md for the common pitfalls.
Platform-specific considerations
Git Bash / MSYS2 (Windows)
Git Bash auto-converts Unix-style arguments to Windows paths. This is the largest single source of cross-platform Bash bugs on Windows.
# The conversion: /foo becomes C:/Program Files/Git/usr/foo
# Disable per-command:
MSYS_NO_PATHCONV=1 command /path/that/should/stay/unix
# Manual conversion
unix_path=$(cygpath -u "C:\Windows\System32")
win_path=$(cygpath -w "/c/Users/username")
# Detect Git Bash
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "mingw"* ]]; then
: # Git Bash
fi
case "${MSYSTEM:-}" in
MINGW64|MINGW32|MSYS) : ;; # MSYS2 / Git Bash environment
esac
# Flags that look like paths
command //e //s # double-slash to suppress conversion
command -e -s # or use dash-optionsFull Git Bash + Windows path notes live in references/windows-git-bash-paths.md.
Linux
GNU coreutils, /proc, systemd integration. Detect via [[ "$OSTYPE" == "linux-gnu"* ]].
macOS
BSD utilities behave differently from GNU. Most common gotchas: sed -i '' (empty string required), date flags differ, readlink -f not available on stock macOS.
if command -v gsed >/dev/null; then SED=gsed; else SED=sed; fiWSL
Effectively Linux. The Windows filesystem is mounted at /mnt/c/. Detect via grep -qi microsoft /proc/version.
Containers
Alpine images ship only /bin/sh (BusyBox). Write POSIX-compliant scripts or apk add bash. Container init quirks: PID 1 must reap children and handle signals. Detect via [ -f /.dockerenv ] or [ -n "$KUBERNETES_SERVICE_HOST" ].
Portable platform-detection template
detect_platform() {
case "$OSTYPE" in
linux-gnu*) echo "linux" ;;
darwin*) echo "macos" ;;
msys*|cygwin*) echo "windows" ;;
*) echo "unknown" ;;
esac
}Full per-platform tables (BSD-vs-GNU coreutils flags, WSL networking, container init patterns) live in references/platform_specifics.md.
Best practices (summary)
The full patterns - function design, error handling, input validation, argument parsing, logging - live in references/in-depth-patterns.md. The headline rules:
- One concern per function; locals declared first; validate input; return non-zero on error.
- Constants
UPPER_CASE; localslower_case; mark immutable valuesreadonly. - Always check exit codes (
if ! cmd,||, traps, or a centralerror_exithelper). - Validate every external input - empty, format, length, charset.
- Use
getoptsor acase-based argument parser; print usage and exit 1 on bad input. - Use a leveled logger that writes to stderr.
Security, performance, testing, debugging, advanced patterns
These each have dedicated sections in references/in-depth-patterns.md:
| Topic | What it covers |
| Security | Command-injection prevention, path-traversal guards, privilege management, secure temp files |
| Performance | Avoiding subshells, bash built-ins vs externals, process substitution, array ops |
| Testing | BATS unit tests, integration test patterns, CI/CD wiring |
| Debugging | set -x, PS4, conditional debug helpers, tracing and profiling |
| Advanced patterns | Safe config parsing, parallel processing, signal handling, retries with backoff |
Read that reference any time you need the canonical code template for one of those topics.
Reference files
references/platform_specifics.md- Detailed platform differences and workaroundsreferences/best_practices.md- Comprehensive industry standards and guidelinesreferences/patterns_antipatterns.md- Common patterns and pitfalls with solutionsreferences/windows-git-bash-paths.md- Git Bash / MSYS path-translation referencereferences/in-depth-patterns.md- Function design, security, performance, testing, debugging, advanced patternsreferences/resources.md- Official docs, style guides, tooling, and learning links
Success criteria
A Bash script written with this skill should:
- Pass
shellcheckwith no warnings - Begin with
set -euo pipefail - Quote every variable expansion
- Print usage on
-h/--help - Decompose into testable functions
- Handle empty input, missing files, and unexpected arguments
- Run on every target platform (Linux/macOS/WSL/Git Bash/container) where it claims support
- Match the Google Shell Style Guide
- Clean up on exit (
trap EXIT) - Be unit-tested with BATS where logic is non-trivial
# Pre-deployment checklist
shellcheck script.sh
bash -n script.sh
bats test/script.bats
./script.sh --help
DEBUG=true ./script.shTroubleshooting
Script fails on a different platform
checkbashisms script.shto surface non-portable constructs.command -v toolto verify a required tool is installed.- Diff command flags between GNU and BSD (
sed --versionetc.).
ShellCheck warnings
- Read the rule explanation (
shellcheck -W SC2086). - Fix the underlying issue; only disable a rule with a justification comment.
Works interactively but fails in cron
- Cron has a minimal
PATH- setPATHexplicitly. - Use absolute paths.
- Redirect stdout/stderr:
./script.sh >> /tmp/cron.log 2>&1.
Performance issues
- Profile with
time. - Enable
set -xto find slow steps. - Replace external invocations with Bash built-ins where possible.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

