A script is not a trick. It is a system. Every operator in this cell is now capable of building automation that fails loudly, cleans up after itself, accepts arguments cleanly, and can be tested, reviewed, and trusted under pressure.
1Every production script starts with set -euo pipefail and a trap on EXIT for cleanup. No exceptions.
2Always double-quote variable expansions: "$VAR". Unquoted variables undergo word splitting and globbing.
3Use [[ ]] not [ ] in bash scripts. Supports regex via =~, glob patterns, and avoids word-splitting traps.
4Use local for all variables inside functions. Without it, every variable is global and will stomp on callers.
5Read files with while IFS= read -r line; do ... done < file -- never with for line in $(cat file).
6Use getopts to parse flags. Define usage() as a function. Check required args after parsing with shift $((OPTIND-1)).
7Return data from functions via echo and capture with $(). Return codes (0-255) signal success or failure type.
8Run shellcheck on every script before deployment. Run bash -n for syntax checks. Use bats for automated tests.
9Avoid subshells in tight loops. Use built-in parameter expansion instead of forking basename, cat, or cut.