bash-scripting-patternslisted
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
|