<aside> 5️⃣
Module 5 — The Shell, Properly
You have been using bash for four modules. This one opens the machine: how it expands what you type before anything runs, where it finds commands, how programs report success, and how their inputs and outputs plumb together. Every later module — and most shell bugs you will ever debug — stand on these mechanics.
Legend used throughout: 🧠 concept → 🧩 analogy → 🧪 exercise → ✅ expected result (hidden) → 🎯 interview questions (hidden)
</aside>
<aside> 🚦
Before you start
You need Modules Module 1 — What Linux Is–Module 4 — Users, Groups, and Permissions — especially: word splitting (2), .bashrc (3), and chmod +x with ./ (4). Nothing new to install. Sandbox: mkdir ~/shellwork && cd ~/shellwork.
</aside>
<aside> ℹ️
This page uses Mermaid diagram blocks. Notion shows them as code by default — click the block and set it to Preview to see the diagram. This reminder appears once per page.
</aside>
<aside> 📖
Official docs: Bash Reference Manual — parameters and expansion
</aside>
🧠 name=value creates a variable; $name anywhere in a later command is replaced by its value before the command runs — the swap you first saw with $SHELL in Module 1, now yours to define. Two rules of the grammar: no spaces around = (the exercise below shows why, memorably), and variable names are case-sensitive with an all-caps convention reserved, informally, for environment variables (A2).
The professional habit that falls out immediately: when unsure what a command will actually receive, put echo in front of it and read the expanded line. Expansion happens the same way either way — echo just shows you the result instead of acting on it.
<aside> 🧩
Real-world analogy — the fill-in-the-blank form letter
A form letter reads "Dear , your order # has shipped". The mail-merge fills every blank from a list, and only then is the letter sent. $name is a blank; the shell is the mail-merge; the command is sent only after every blank is filled.
Where the analogy stops working. Mail-merge software refuses to send with an unfilled blank. The shell fills an unset variable with nothing — silently — and sends anyway. The letter goes out reading "Dear , your order # has shipped". Half of Part B and one capstone ticket exist because of this exact behaviour.
</aside>
🧪 Exercise A1.1 — Define, expand, inspect
cd ~/shellwork
target=web-01 # define (no spaces around =)
echo $target # expand it
echo deploying to $target # expansion happens inside any command line
echo target # no $: just the word itself
🧪 Exercise A1.2 — The spaces mistake, on purpose (fails, famously)
name = "web-01" # looks reasonable; is not
<aside> 📖
Official docs: environ(7) · env(1)
</aside>
🧠 Every command you run starts a child process — a separate program (Module 8 makes this precise) that receives a copy of its parent's environment: the subset of variables marked for export. A plain name=value stays private to your shell; export name promotes it into the environment, and from then on every child — and their children — receives a copy at start. Inspect the whole environment with env (or printenv); you have already met its residents: HOME, PATH, SHELL, USER, LANG.
This is the configuration channel of modern operations: services read database URLs, log levels, and feature flags from environment variables — which is why understanding the copy semantics below is not trivia.