Meet the shell
Learn what a shell is, how a command is built, and how to get help without leaving the terminal.
- Explain how the terminal, the shell and the commands you run fit together
- Break a command line into the command, its options and its arguments
- Print text with echo and printf, and find help with type, help, man and --help
Welcome aboard Kestrel Station, a research outpost in low orbit. Every system up here - life support, cargo robots, the coffee machine - runs on Linux, and the crew talks to all of it through one tool: the shell. You’re the newest engineer, and by the end of this track you’ll be the one writing the scripts that keep the station humming.
Three pieces work together whenever you “use the command line”:
- The terminal (Terminal, iTerm2, Windows Terminal, the panel in VS Code) is just a window that shows text and sends your keystrokes.
- The shell is the program running inside it. It reads what you type, works out what you mean, runs programs, and shows their output.
- Commands are the programs (and shell built-ins) that do the actual work:
lslists files,grepsearches text,gitmanages code.
Bash - the Bourne Again SHell - is the most widely used shell. It’s the default on most Linux servers, in Docker containers and CI pipelines, and it’s one install away on macOS (whose default is now the very similar zsh) and Windows (Git Bash or WSL). Everything you learn here carries over to almost every shell you’ll meet.
Anatomy of a command
When the shell is ready, it shows a prompt - often something like ada@kestrel:~$. The $ means “type here”. (A # usually means you are the all-powerful root user, so be careful.) In lessons, a leading $ marks what you type; don’t type the $ itself.
A command line is a list of words separated by spaces. The first word is the command; the rest are passed to it:
1ls -l -a /etc
2│ │ │ └── argument: what to work on
3│ └──┴───── options (flags): how to do it
4└─────────── commandShort options start with one dash and can usually be combined (ls -la is ls -l -a). Long options start with two dashes and are spelled out (ls --all). Spaces matter: ls -la lists files, while ls - la asks for two files named - and la.
Try it
Command, option or argument?
Each item is one word from a command line (shown in brackets). Sort it into the role it plays.
“[ls] -la /home”
“ls [-la] /home”
“ls -la [/home]”
“grep [--count] ERROR station.log”
“grep --count ERROR [station.log]”
“grep --count [ERROR] station.log”
“[mkdir] -p logs/today”
Your first commands: echo and printf
echo prints its arguments separated by single spaces, then a newline. printf takes a format string first and fills its %s (string) and %d (whole number) placeholders with the remaining arguments - and it only adds a newline where you write \n. These examples run for real: press Run, then Edit and experiment.
1echo Hello, Kestrel!
2echo "Spaces inside quotes are kept"
3echo Spaces outside quotes are not
4printf '%s has %d crew aboard\n' Kestrel 6
5printf '%-10s|%5s|\n' left rightHello, Kestrel! Spaces inside quotes are kept Spaces outside quotes are not Kestrel has 6 crew aboard left |right|
Notice line 3: the shell splits the line into words at any run of spaces before echo ever sees it, so echo receives five tidy words and joins them with single spaces. Quotes keep text together as one word. You’ll lean on that idea constantly. In printf, %-10s pads a string to 10 characters, left-aligned, and %5s right-aligns it in 5 - perfect for tables.
Getting help
Nobody memorizes every option. Experienced engineers look things up constantly - from the terminal itself:
| Command | What it tells you |
|---|---|
type ls | what a name is: a built-in, a program on disk, an alias or a function |
help cd | the manual for a Bash built-in (like cd, echo, read) |
man ls | the full manual page for a program (press q to quit, /word to search) |
ls --help | a quick summary that most GNU programs print |
Some handy keys: Tab completes names, ↑ recalls earlier commands, Ctrl+R searches your history, Ctrl+C cancels the running command, and Ctrl+L clears the screen.
1type echo
2type cd
3type -t grep
4whoamiecho is a shell builtin cd is a shell builtin file wandbox
Key takeaways
The terminal shows text; the shell interprets your commands; commands do the work.
A command line is split into words: the command, then options (starting with
-or--), then arguments.echoprints its words;printfgives precise control with a format string and%s/%dplaceholders.Use
type,help,manand--helpto find out what something is and how to use it.
Lesson quiz
7 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write Bash scripts
Write a script in the editor and run it for real against sample input. Each run gets a fresh Linux sandbox with Bash 5.2 and the GNU tools on Wandbox, a free public service - so experiment freely, even with rm. Your script and test input are sent there.
Print the station banner
Print exactly these three lines:
=== KESTREL STATION ===
Orbit: low
Crew: 6- Prints the banner
Your script runs with Bash 5.2 and GNU tools on Wandbox, a free public service, in a fresh sandbox each time. Your script and test input are sent to that service.
Line up the supply table
Use printf to print a table of supplies. Each row is the item left-aligned in 8 characters, a space, then the amount right-aligned in 4:
water 120
oxygen 87
coffee 3One printf call with a single format string and six arguments can print all three rows.
- Prints an aligned table
Your script runs with Bash 5.2 and GNU tools on Wandbox, a free public service, in a fresh sandbox each time. Your script and test input are sent to that service.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…