← ClaudeAtlas

bash-scripting-patternslisted

Bash + shell scripting discipline — strict header (set -euo pipefail; IFS), naming conventions (kebab-case scripts, snake_case functions/vars, SCREAMING_SNAKE_CASE constants), always-quoted variables, defaults via ${var:-default}, getopts for arguments, structured logging to stderr, cleanup via trap, no backticks (use $(cmd)), no eval with user input, no rm -rf on unset vars, ShellCheck strict + shfmt format-check enforced. Auto-fires on shell scripts.
Nmor/the-claude-council · ★ 9 · Code & Development · score 69
Install: claude install-skill Nmor/the-claude-council
> Migrated 2026-06-02 from `~/.claude/rules-library/bash/` as part of the lazy-rules-loading plan. Phase H will delete the source files. # bash-scripting-patterns <!-- ============================================================ Section: bash/coding-style.md ============================================================ --> # Bash / Shell Coding Style > Auto-fires on every `*.sh`, `*.bash`, `*.zsh`, file with > `#!/usr/bin/env bash` or `#!/bin/bash` shebang, `.bashrc`, > `.zshrc`. Standards: **Bash Reference Manual (GNU)**, **Google > Shell Style Guide**, **ShellCheck**, **shfmt**, **POSIX sh > spec** (when portability required). ## Core Principle **Bash is for short-lived scripts (< 100 LOC). For anything longer, use Python / Go / Rust. Every script starts with `#!/usr/bin/env bash` + `set -euo pipefail`; arguments handled via `getopts` or `getopt -l`; quoted variables ALWAYS; functions return integer exit codes; output structured for the next pipe in line.** ## Mandatory header ```bash #!/usr/bin/env bash # # script-name.sh — one-line summary # # Usage: # script-name.sh [OPTIONS] <ARG> # # Options: # -h, --help show this help # -v, --verbose enable verbose logging # set -euo pipefail IFS=$'\n\t' # safer word-splitting ``` Why each flag: - `-e` — exit on any command failure - `-u` — exit on unbound variable - `-o pipefail` — exit if any pipe component fails (not just the last) - `IFS=$'\n\t'` — prevents space-splitting of filenames ## Naming |