Course

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

  1. 01
    Your first script

    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.

    Beginner · 14 min read

    Not started
  2. 02
    Values in variables, and quoting

    Naming a value, the strict rule about spaces around the equals sign, and the everyday difference between "$name" and a pair of single quotes.

    Beginner · 16 min read

    Not started
  3. 03
    Exit codes and joining commands

    Every command answers with a number, $? holds the last one, and && and || let you decide what runs next without writing an if at all.

    Beginner · 15 min read

    Not started
  4. 04
    Decisions with if

    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.

    Beginner · 18 min read

    Not started
  5. 05
    Matching with case

    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.

    Intermediate · 14 min read

    Not started
  6. 06
    Loops that repeat work

    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.

    Intermediate · 18 min read

    Not started
  7. 07
    Functions and their arguments

    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.

    Intermediate · 20 min read

    Not started
  8. 08
    Arrays of values

    One name for a list of values: reading items by their position, counting them, adding one, and the quoting that keeps each item whole.

    Intermediate · 16 min read

    Not started
  9. 09
    Arithmetic in the shell

    Working with numbers: the double round brackets, the everyday operators, and the one rule that surprises everybody — the shell counts in whole numbers only.

    Advanced · 15 min read

    Not started
  10. 10
    Pipelines and text tools

    The vertical bar that hands one command output to the next, and the seven small tools that most shell work is built from.

    Advanced · 20 min read

    Not started
  11. 11
    Captured output, sed and awk

    Keeping what a command printed in a variable, and the two tools you reach for when a line of text needs changing or reshaping.

    Advanced · 20 min read

    Not started
  12. 12
    Putting it together: a log report

    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.

    Advanced · 22 min read

    Not started