Shell Scripting (bash)
From your very first command to robust, portable bash scripts. You learn what the shell really does with the line you type (how it splits, expands and quotes it, how it forks and execs programs, how file descriptors and pipes connect them) and use that to work with files, text and processes. Every lesson has a real bash shell in a throwaway Debian container with a workspace at /work, so you can explore, break things and try again. No network and no root inside the box.
- The Shell, the Terminal and the Kernel
What a shell is, how a command line is built, exit statuses, and how to get help.- Terminal, shell and kernel · 30 min · 4 exercises
- Anatomy of a command · 35 min · 4 exercises
- Exit status and command lists · 35 min · 4 exercises
- Getting help: man, help and --help · 30 min · 4 exercises
- The Filesystem and Navigation
The directory tree, absolute and relative paths, moving around, and reading ls -l.- The directory tree · 30 min · 4 exercises
- Moving around: cd, pwd and paths · 35 min · 4 exercises
- Looking closely: ls -l, file types and stat · 40 min · 3 exercises
- Working with Files
Creating, viewing, copying, moving and deleting files; links and inodes; awkward file names.- Creating and viewing files · 35 min · 4 exercises
- Copying, moving and removing · 40 min · 4 exercises
- Inodes, hard links and symbolic links · 40 min · 4 exercises
- Awkward names and first wildcards · 40 min · 5 exercises
- Permissions and Users
Users, groups and root; the rwx bits; chmod in symbolic and octal form; umask and directories.- Users, groups and root · 35 min · 4 exercises
- Reading and changing permissions · 40 min · 4 exercises
- Octal modes, umask and directory permissions · 45 min · 6 exercises
- Redirection and Pipes
File descriptors, redirecting stdout and stderr, pipelines and how the kernel connects them.- File descriptors and output redirection · 40 min · 4 exercises
- Standard error, /dev/null and ordering · 40 min · 4 exercises
- Pipes and pipelines · 40 min · 5 exercises
- Pipeline exit status, tee and process substitution · 40 min · 4 exercises
- Text Processing
The classic Unix text tools: grep, sort, uniq, cut, tr, wc, sed and awk, and how to combine them.- Searching with grep and basic regular expressions · 45 min · 4 exercises
- Slicing and counting: sort, uniq, cut, tr, wc · 45 min · 5 exercises
- Editing streams with sed · 45 min · 5 exercises
- awk: fields, patterns and actions · 50 min · 5 exercises
- Answering questions with pipelines · 50 min · 4 exercises
- Variables, Quoting and Expansion
The heart of bash: variables and the environment, quoting, and the order in which a line is expanded.- Variables and the environment · 40 min · 4 exercises
- Quoting: single, double and backslash · 40 min · 4 exercises
- How bash expands a command line · 45 min · 4 exercises
- Word splitting, IFS and why you quote · 45 min · 4 exercises
- Command substitution and arithmetic · 40 min · 4 exercises
- Parameter expansion: defaults, lengths and errors · 40 min · 3 exercises
- Your First Scripts
Script files, the shebang, running vs sourcing, arguments, reading input and exit statuses.- Script files, the shebang and chmod · 40 min · 4 exercises
- Arguments: $1, $#, "$@" and shift · 45 min · 4 exercises
- Reading input and returning a status · 45 min · 4 exercises
- Writing scripts people can use · 45 min · 3 exercises
- Conditionals and Tests
if, test and [ ], the safer [[ ]], arithmetic tests, and case.- if and the test command · 40 min · 4 exercises
- [[ ]]: strings, patterns and files · 40 min · 4 exercises
- Arithmetic with (( )) · 35 min · 4 exercises
- case statements · 35 min · 3 exercises
- Loops
for, while and until loops; reading input line by line; loop control and the subshell trap.- for loops · 40 min · 4 exercises
- while, until and counters · 40 min · 4 exercises
- Reading lines and fields safely · 45 min · 3 exercises
- break, continue and loops in pipelines · 40 min · 3 exercises
- Functions
Defining functions, arguments and return statuses, local scope, and organizing scripts.- Defining and calling functions · 40 min · 4 exercises
- Scope, local and returning values · 45 min · 4 exercises
- Organizing a script: main, libraries and source · 45 min · 3 exercises
- Robust Scripts
set -euo pipefail and its limits, traps and cleanup, error handling, and the classic pitfalls.- Strict mode: set -e, -u and pipefail · 40 min · 3 exercises
- Traps, temporary files and cleanup · 40 min · 3 exercises
- Error handling patterns · 40 min · 3 exercises
- The classic pitfalls · 45 min · 3 exercises
- Processes, Jobs and Signals
Processes and /proc, fork and exec in depth, background jobs, signals, subshells and exec.- Processes, PIDs and /proc · 40 min · 4 exercises
- Background jobs and wait · 45 min · 3 exercises
- Signals and kill · 45 min · 3 exercises
- Subshells, groups and exec · 45 min · 4 exercises
- Globbing, find and xargs
Glob patterns in depth, finding files by any property, and running commands on many files safely.- Globbing in depth · 40 min · 4 exercises
- find: tests and actions · 50 min · 4 exercises
- xargs and null-separated names · 45 min · 4 exercises
- Arrays, Here-docs, Strings and Regex
Indexed and associative arrays, here-documents, string manipulation and regex matching in bash.- Indexed arrays · 40 min · 4 exercises
- Associative arrays · 40 min · 4 exercises
- Here-documents and here-strings · 35 min · 4 exercises
- String manipulation · 45 min · 4 exercises
- Regular expressions in bash · 45 min · 4 exercises
- Portability and Debugging
POSIX sh versus bash, finding bashisms, and debugging with bash -x, PS4 and friends.- POSIX sh and bashisms · 45 min · 4 exercises
- Debugging scripts · 45 min · 4 exercises
- Style, tools and where to go next · 40 min · 3 exercises
- Practical Projects
Putting it together: a log analyzer, a backup script with rotation, and a safe batch renamer.- Project: log analyzer · 75 min · 4 exercises
- Project: backup with rotation · 75 min · 5 exercises
- Project: batch renamer · 75 min · 4 exercises