Text Processing
7 pages · ~5 min✓ Reviewed
Builds on Filesystem and Permissions. Next up: Shell Scripting.
Streams, Pipes and Redirection Model
1. Streams and Pipes
- stdin = fd 0, stdout = fd 1, stderr = fd 2
- A filter reads stdin and writes stdout
a | bwires a's stdout to b's stdin- Both run at the same time
- Only stdout travels; stderr still hits the terminal
2. Redirection
| Operator | Effect |
|---|---|
> | truncate and write a file |
>> | append to a file |
< | feed a file to stdin |
2>file | stderr to file |
2>&1 | merge stderr into stdout |
&>file | both streams to file (bash) |
bash
cmd >f 2>&1 # works: both in f cmd 2>&1 >f # stderr stays on screen
order matters
Left to right
2>&1 copies where stdout points at that moment.