ch03 · foundation · 80-110 min

streams, pipes, and redirection

Understand stdin, stdout, stderr, pipes, redirection, quoting, and shell expansion.

You can build small pipelines and explain where data is flowing.

pipesredirectionquotingxargsshell
Teaching diagramch03 · mental model
three streams, redirected separately stdin fd 0 command grep / sort stdout fd 1 > file stderr fd 2 2> file stdout pipes to next stage; stderr stays on screen > redirects fd1 only — fd2 needs its own 2>

shows: A command reads stdin (fd0) and writes two independent outputs — stdout (fd1) and stderr (fd2) — each redirectable on its own, so `>` captures data while `2>` captures diagnostics.

does not prove: It shows the wiring of the three streams, not that any given command actually sends errors to stderr — a few tools misroute diagnostics to stdout, so you still confirm by inspecting both targets.

Lessons in this chapter

  1. ch03/l01 stdin, stdout, stderr 2> Know which stream carries data and which carries diagnostics.
  2. ch03/l02 Pipelines and filters sort | uniq -c Compose small tools into an evidence-producing report.
  3. ch03/l03 Quoting and shell expansion printf '%s\n' ./*.log Prevent the shell from changing your command before the program sees it.
capstone

search pipeline report

Build a null-safe pipeline that finds copied log files, searches for one term, counts matches, and writes a report.

Deliverable

A report plus the tested pipeline stages.

Success criteria

  • Each stage has a named purpose.
  • Filenames with spaces survive.
  • Errors are not hidden inside data output.
Terminal Drill companion

Searching

After you can explain pipeline input and output without relying on trial and error.

Train after the lesson