Bash Scripting & Command Line Automation
Pipes, Filters, Shell Variables, Cron Jobs & Defensive Scripting
8 modules, 40 lessons: The Shell And The Command Line; Quoting And Word Splitting; Redirection, Pipelines And Text; Variables And Expansion; Writing Scripts; Functions And Scripts That Do Not Break; Debugging, Style And Portability; The Shell As A System Tool.
Beginner · 4 hours · 40 lessons · 235 labs
Who it is for
Beginner level.
For anyone who types commands and wants the computer to repeat the work for them: support and operations staff, analysts, testers and new engineers.
What you don't need yet:
- No programming experience: scripting starts from the first line
- No Linux computer of your own: labs run in a sandboxed shell
- You don't need to know grep, sed or awk yet
What helps:
- Opening a terminal and typing a command
Before you start:
- Basic terminal usage
Take first:
- Linux Fundamentals & Systems Administration — Beginner
Take next:
- Advanced Git Internals & Distributed Workflows — Beginner
- Ansible Configuration Management at Scale — Intermediate
- Red Hat Certified System Administrator (EX200) Exam Prep — Intermediate
Learning paths:
Nobody needs to know everything before they start. Each course builds on the one before, so a learning path takes you there step by step.
Labs
235 labs, 111 of them graded: you write the code, it runs, and graded labs check the result. The outline lists each lesson's labs.
What is free
Start free: First module free with an account. Pro: Every course, lab, handbook, practice exam and certificate.
- Pro monthly — $29 a month. Every course, lab, handbook, practice exam and certificate
- Pro yearly — $249 a year. Every course, lab, handbook, practice exam and certificate
Course outline
The Shell And The Command Line
- What A Shell Is, And What Bash Is (3 labs): You will know the difference between a terminal and a shell, and what Bash is.
- Which Shell Am I In, And Getting Bash Five (7 labs): You will be able to check your current shell and its version, and know how to get bash five.
- Moving Around: pwd, ls, cd And Paths (6 labs): You will be able to navigate the file system and understand absolute and relative paths.
- Making, Copying, Moving And Removing (8 labs): You will be able to create, copy, rename, and delete files and directories.
- Help, History, Completion And Aliases (8 labs): You will be able to read manuals, use command history, auto complete paths, and define aliases.
Quoting And Word Splitting
- What Bash Does To A Line Before It Runs It (4 labs): You will be able to name the order of the shell expansions and predict how a line is rewritten before it runs.
- Single Quotes, Double Quotes, Backslash (5 labs): You will be able to choose between single quotes, double quotes and a backslash, and get a single quote inside a single quoted string.
- The Unquoted Variable: Splitting And Globbing (5 labs): You will be able to recognise the failures an unquoted variable causes and quote expansions so they cannot happen.
- The Field Separator, And Reading Lines Safely (5 labs): You will be able to control word splitting with the field separator and read a file line by line without losing anything.
- Arrays, And Why Dollar At Is Not Dollar Star (4 labs): You will be able to build and expand arrays and forward a script's arguments without damaging them.
Redirection, Pipelines And Text
- Standard Input, Output And Error (4 labs): Understand the three standard streams and how commands use them to read and write data.
- Redirection: Truncate, Append, Both Streams (4 labs): You will be able to capture output and errors separately or together, discard them, and avoid destroying the file you are reading.
- Pipelines, tee And Process Substitution (6 labs): You will be able to chain commands with a pipeline, keep a copy of the data mid-pipeline with tee, and feed a command a file name that is really another command.
- Finding Lines: grep And Regular Expressions (5 labs): You will be able to search files and whole trees with grep, and describe what you are looking for with a regular expression.
- Reshaping Text: cut, sort, uniq, tr, sed, awk (5 labs): You will be able to slice columns, order rows, count repeats, translate characters and summarise fields with the standard text tools.
Variables And Expansion
- Shell Variables, The Environment And export (4 labs): Define shell variables, mark them for export to child processes, and explain the difference between local shell variables and the environment.
- Parameter Expansion: Defaults, Length, Slices (5 labs): Use parameter expansion to provide default values, measure string length, and extract slices of a string.
- Trimming, Replacing And Changing Case (6 labs): Use parameter expansion to trim prefixes and suffixes, replace text, and change the case of strings.
- Command Substitution And Subshells (5 labs): Capture the output of a command using command substitution, and explain how subshells isolate state changes like working directories and variables.
- Arithmetic: Double Parentheses, let And bc (5 labs): Perform integer math using double parentheses and the let command, and calculate floating point numbers using the basic calculator.
Writing Scripts
- Shebangs, Permissions And Three Ways To Run (4 labs): Write a script with a shebang, make it executable, and run it directly or by passing it to bash.
- Exit Codes, And What Success Means (7 labs): You will be able to read and set the exit status of a command to control script execution.
- Conditionals: test, Brackets, Double Brackets, case (6 labs): Use if statements with test, single brackets, and double brackets to branch logic, and write case statements for multiple choices.
- Loops: for, while, until, break, continue (11 labs): Write loops to repeat commands, and use break and continue to control them.
- Script Input And Output: read, Heredocs, printf (7 labs): Read user input interactively, read file lines in a loop, write multi-line text cleanly, and format variables predictably.
Functions And Scripts That Do Not Break
- Functions, local And declare (12 labs): Write reusable shell functions that do not leak variables into the global scope.
- Arguments: Dollar One, Dollar At, shift (7 labs): Read a script's arguments, pass them on intact, and walk through them with shift.
- Option Parsing With getopts (6 labs): Parse single letter flags and options that carry a value with the getopts builtin.
- set -e, set -u And pipefail: Promises And Traps (6 labs): Turn on the three safety options and recognise the failures they still let through.
- trap, Cleanup And Temporary Files (7 labs): Clean up reliably on the way out using trap, a temporary directory and an idempotent cleanup function.
Debugging, Style And Portability
- Debugging: set -x, bash -n And Reading The Error (6 labs): Check a script without running it, trace what it really does, and read what a bash error message is telling you.
- ShellCheck (7 labs): Run ShellCheck over a script, read a finding by its code and severity, and silence one line with a reason.
- Style That Prevents Bugs (6 labs): Write shell the way the Google style guide does, and recognise the size at which a script should become a program in another language.
- POSIX sh Versus Bash (7 labs): Tell a bashism from portable shell, and know which program will read your script when the shebang says sh.
- eval, And What To Use Instead (6 labs): Recognise eval as a code injection hole and replace it with an array, an indirect expansion or a name reference.
The Shell As A System Tool
- Processes, Jobs And Signals (5 labs): You will be able to list processes, move jobs between the foreground and the background, and send named signals to stop them.
- Permissions And Ownership (6 labs): You will be able to read a permission string, set modes in both the symbolic and the numeric form, and explain what a umask and a directory execute bit do.
- find And xargs (5 labs): You will be able to select files by name, type, depth and emptiness with find, and hand the results to another command without a file name ever breaking it.
- Archives, Transfers And The Network (5 labs): You will be able to build, inspect and unpack a compressed archive, and know which command to reach for when a script has to copy or fetch something over the network.
- Scheduling, Monitoring And A Script That Reports (5 labs): You will be able to read and write a crontab line, and build the report script this course leaves behind for the ones that follow it.