Bash
Move from typing commands to writing scripts that survive Monday morning. Loops, exit codes, traps, defensive scripting.
beginner16 labs
Recommended first
You can still start this course now. Earlier courses give you the mental model the labs here assume.
By the end you'll be able to
- Write scripts that fail loudly instead of silently
- Handle arguments, exit codes, and traps like a grown-up
- Loop over real data without choking on whitespace
- Debug a broken script in production without rewriting it
Labs
- 01StartMake a script runnableA script is a text file with a shebang on line one and the execute bit set. Three small steps to turn typed commands into a program.15 min
- 02StartRead what every command returnsEvery command returns a number when it finishes. Zero means success, anything else means failure. This number is how scripts detect errors.15 min
- 03StartPass arguments to scripts$1 is the first argument. $@ is all of them. $# is how many. Three variables that turn a script from fixed to reusable.15 min
- 04StartLocal variables vs exported variablesA plain assignment lives in the current shell. export marks the variable so child processes inherit it. The same name behaves differently depending on which side of export you set it.15 min
- 05StartParameter expansion for safe scriptsBash parameter expansion does more than `$VAR`. Default values, stripping a suffix, and stripping a prefix all come from the same `${...}` syntax.20 min
- 06StartBranch on conditions with ifBash `if [ ... ]; then ... elif ... else ... fi` is the workhorse of every shell script. Write a script that decides between two answers based on a numeric argument.15 min
- 07StartIterate with the three for-loop formsA for loop walks a list of values one at a time. The list can be words you type, files a glob expands to, or the output of another command.20 min
- 08StartRead a file line by line with whileA for loop splits on whitespace and breaks on lines that contain spaces. while read pulls one full line at a time, which is the right shape for log files, CSVs, and any list with one item per line.15 min
- 09StartBranch on patterns with caseA long if/elif chain that compares one variable against many values is what case was built for. Cleaner syntax, faster to read, and a wildcard arm for the unmatched fallthrough.15 min
- 10StartDefine functions and scope variablesFunctions group commands behind a name. local keeps variables inside the function so they do not leak into the caller.15 min
- 11StartReuse code with sourcesource loads another script into the current shell. The variables and functions it declares become yours, without spawning a child process.15 min
- 12StartDefensive scripting with set -euo pipefailA bare Bash script keeps going after errors and treats unset variables as empty strings. set -euo pipefail flips those defaults so problems surface early.20 min
- 13StartGuarantee cleanup with trap EXITUse trap to remove temporary files even when a script errors out or exits early.20 min
- 14StartParse JSON with jqjq is the standard tool for reading JSON in a shell pipeline. Extract fields, index arrays, strip quotes.15 min
- 15StartParse command-line flags with getoptsUse the built-in `getopts` loop to read short flags in a script. Handle a value-bearing flag and a plain switch.25 min
- 16StartCapstone, a deploy gate scriptAn open-ended problem with no prescribed solution. Write a script that reads a service status file, reports how many services are down, and exits non-zero when any are, so a deploy pipeline can gate on it. Any approach that behaves correctly passes.25 min