Goal: shell scripts that are safe, portable, and fail loudly.
Use for:
- automation, CI steps, and glue scripts
- reviewing fragile or unsafe shell code
- hardening scripts against edge cases
Workflow:
- Start with set -euo pipefail for strict failure.
- Quote every variable expansion: "$var", "${arr[@]}".
- Check for required commands and inputs up front.
- Use functions and local variables for structure.
- Prefer printf over echo for predictable output.
- Verify with shellcheck and a dry run.
Idioms:
- "${var:-default}" for fallbacks
- [[ ... ]] over [ ... ] for tests
- trap for cleanup on exit
- mktemp for temporary files
Rules:
- always quote expansions to survive spaces and globs
- set -euo pipefail unless you have a reason not to
- validate inputs before destructive actions
- run shellcheck; treat its findings as real bugs