Bash Cheatsheet
Power user.
Overview
Bash is the default shell on most Linux systems and the lingua franca of operations scripting. The features that make Bash powerful (pipelines, parameter expansion, process substitution, job control) also make it dangerous when used naively (word splitting on unquoted variables, silent failures without -e, unset-variable bugs without -u). Fluency means knowing both the powerful patterns and the defensive incantations that prevent the patterns from biting.
- Pipelines. Combine simple tools into composable workflows; the Unix philosophy at the shell level.
- Variables and parameter expansion. ${var:-default}, ${var##*/}, ${var:0:5} replace external tools for string operations.
- Process substitution. <(command) treats output as a file; supports diff against live data without temp files.
- Job control plus conditionals and loops. Background, foreground, suspend; for, while, if, case as first-class for real scripts.
The approach
The practical approach is set -euo pipefail at the top of every script (exit on error, unset variable, or pipe failure), quote every variable expansion ("$var" not $var) to avoid word-splitting bugs, use ${var:-default} for compact defaults, prefer arrays over space-separated strings to avoid IFS hacks, and run shellcheck in CI to catch bugs before they ship.
- set -euo pipefail. Exit on error, on unset variable, on pipe failure; catches bugs early rather than letting them produce silent failures.
- "$var" not $var. Quote variables; avoids word-splitting bugs that bite under unusual inputs (filenames with spaces, etc.).
- ${var:-default}. Defaulting expansion; compact and readable.
- Arrays for lists plus shellcheck. arr=(a b c) for proper list handling; shellcheck in CI catches bugs before they ship.
Why this compounds
Bash fluency compounds across operations. Each script captures operational knowledge that future operators reuse; each defensive pattern (set -euo pipefail, quoting, shellcheck) prevents bug classes the team would otherwise hit repeatedly. After a year of disciplined use, the team has a script library that survives team changes.
- Faster operations. Bash one-liners replace multi-step manual work; the investigation question becomes a one-line command.
- Reusable scripts. The team’s script library grows; new joiners inherit the patterns rather than re-inventing them.
- Robust automation. set -euo pipefail produces failure-aware scripts; silent failures become loud failures.
- Institutional knowledge. Each script teaches the language; the team builds vocabulary that transfers across operations.
Bash fluency is an operational discipline that pays off across years. Nova AI Ops integrates with operations telemetry, surfaces script patterns, and supports the team’s automation discipline.