Bash from the ground up
The shell, one script at a time
- Beginner
- 12 chapters
- 208 min read
Learn the shell by writing it: printing and quoting, exit codes, decisions with if and case, loops, functions, arrays, arithmetic, and the pipelines of small text tools that shell work is really made of — ending with a capstone report that builds its own data and filters it.
What You'll Learn
- Run a script, and print with echo and with printf
- Keep values in variables, and know what quoting does to them
- Read exit codes, and join commands with && and ||
- Branch with if, test numbers, text and files, and match patterns
- Choose between several possibilities with case
- Repeat work with for, while and a range of numbers
- Write functions that take arguments and answer with text or a code
- Hold a list in an array, and loop over it without splitting it
- Do arithmetic with whole numbers, and know where the fraction goes
- Filter text with grep, sort, uniq, cut, head, tr and wc
- Capture command output in a variable, and edit text with sed and awk
- Build a data file, filter it with a pipeline and print a summary
Prerequisites
- No programming experience needed — this course starts at a script file
- A terminal you have typed a command or two into makes the first chapters quicker
Course Content
- 01Your first scriptNot started
What a shell script is, how to print a line with echo and with printf, and why those two commands do not always agree about a backslash.
- 02Values in variables, and quotingNot started
Naming a value, the strict rule about spaces around the equals sign, and the everyday difference between "$name" and a pair of single quotes.
- 03Exit codes and joining commandsNot started
Every command answers with a number, $? holds the last one, and && and || let you decide what runs next without writing an if at all.
- 04Decisions with ifNot started
Branching on a test: if, else and elif, the test brackets, the different spellings for numbers and for text, and the safer double-bracket form.
- 05Matching with caseNot started
One value, several patterns, and a branch for each: how case replaces a ladder of tests, and why its patterns are not quite the tests you already know.
- 06Loops that repeat workNot started
Three ways to repeat: for over a list of words, while with a counter, and the brace range that writes a run of numbers for you.
- 07Functions and their argumentsNot started
Naming a block of lines, passing values in as $1 and $2, collecting them with "$@", and the two ways a function can hand an answer back.
- 08Arrays of valuesNot started
One name for a list of values: reading items by their position, counting them, adding one, and the quoting that keeps each item whole.
- 09Arithmetic in the shellNot started
Working with numbers: the double round brackets, the everyday operators, and the one rule that surprises everybody — the shell counts in whole numbers only.
- 10Pipelines and text toolsNot started
The vertical bar that hands one command output to the next, and the seven small tools that most shell work is built from.
- 11Captured output, sed and awkNot started
Keeping what a command printed in a variable, and the two tools you reach for when a line of text needs changing or reshaping.
- 12Putting it together: a log reportNot started
A capstone that uses the whole course once: build a data file, filter it with a pipeline, keep the answers in variables, and print a summary that lines up.
