Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Bash

The shell that runs on almost every server and laptop: commands, quoting and expansions, pipes, scripts, text processing and safe automation, from a first command to professional practice.

Bash, the Bourne-Again SHell, is the GNU Project's command interpreter, first released by Brian Fox in 1989 as a free replacement for the Unix Bourne shell. It is the default interactive shell on most Linux systems, it is what most shell scripts are written for, and it is the language of countless build scripts, deployment pipelines, container entry points, CI jobs and one-off automations. Knowing it well means being at home on any server and being able to glue programs together in a few lines.

This course is for anyone who knows what a variable, a loop and a function are: the Start level of Lumenary CS or equivalent experience in any language. It starts with what a shell and a terminal are and how a command line is read, works through quoting and expansions (the part of Bash that surprises everyone), pipes and redirection, conditionals, loops, functions and arrays, then the classic text tools (grep, sed, awk, sort and friends), and ends with writing scripts that fail safely, checking them with ShellCheck, managing processes and jobs, and a complete automation project.

Bash comes with almost every Linux distribution. On macOS the built-in Bash is a very old version (3.2), so install a current one with a package manager such as Homebrew, or use the default zsh for interactive work and Bash for scripts; on Windows, use the Windows Subsystem for Linux or Git Bash. The source and documentation are at gnu.org/software/bash. There is no official online playground, but ShellCheck checks scripts in the browser. Every complete script in these lessons was run with GNU Bash 5.1 and the GNU core utilities by Lumenary's test suite, and the output shown is the output it printed; the lessons point out features added in Bash 5.2 and 5.3. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 3 lessons

Foundations

What a shell and a terminal are, how Bash reads a command line, quoting and the expansions that happen before any command runs, and connecting programs with pipes and redirection.

  1. 1The shell and the terminalWhat a shell is, where Bash came from, how it reads and runs a command line, and your first script. 45 min
  2. 2Quoting, variables and expansionsHow Bash rewrites every command line before running it, and why "quote your variables" is the most important rule in shell scripting. 55 min
  3. 3Pipes and redirectionStandard input, output and error, sending them to files and to each other, and building pipelines out of small programs. 50 min

Practice · 3 lessons

Practice

Exit statuses, conditionals and loops; functions, arguments and arrays in real scripts; and answering questions about data with grep, sed, awk, sort and the other classic text tools.

  1. 4Exit statuses, conditionals and loopsHow the shell decides what is true, the four ways to test a condition, case statements, and every kind of loop. 50 min
  2. 5Functions, arguments, arrays and script structureWriting functions that behave, handling arguments and options like a real command, storing lists and tables in arrays, and laying out a script professionals would accept. 55 min
  3. 6Text processing with grep, sed, awk and friendsRegular expressions, the classic filters, and how to answer real questions about data by building a pipeline one stage at a time. 60 min

Professional · 2 lessons

Professional

Write scripts that fail safely and pass ShellCheck, manage processes, jobs and signals, and build a complete automation script the way professionals do.

  1. 7Scripts that fail safelyStrict mode and its caveats, cleaning up with trap, checking scripts with ShellCheck, debugging with xtrace, and the defensive habits that keep shell scripts from doing damage. 55 min
  2. 8Processes, jobs and an automation projectBackground jobs, waiting and parallelism, signals and graceful shutdown, job control at the prompt, and a complete, safe automation script, scheduled to run on its own. 65 min

Further reading and resources