Recognize the three standard streams
#Descriptor 0 is stdin, 1 is stdout and 2 is stderr. Redirecting stdout alone does not capture diagnostic output.
Fragment
Reference
Read commands, quoting, streams, paths and scripts.
POSIX sh (2017 baseline), Bash additions and named Unix tools. Examples are independent fragments; file paths are illustrative. Bash-only syntax is labeled. macOS and Linux utility flags can differ.
POSIX sh docs POSIX Shell Command Language ↗
Descriptor 0 is stdin, 1 is stdout and 2 is stderr. Redirecting stdout alone does not capture diagnostic output.
Fragment
> creates or truncates a file. >> appends. 2>&1 duplicates the current destination of descriptor 1; redirections are processed left to right.
Fragment
2>&1 > run.log leaves stderr at the old stdout destination.
| connects the left command’s stdout to the right command’s stdin. Stderr stays separate unless redirected.
Fragment
Pipeline components can run concurrently; do not rely on a pipeline loop changing variables in the caller.
In the 2017 POSIX baseline, the pipeline status comes from its last command. A successful consumer can hide a failed producer.
Fragment
A quoted here-document delimiter suppresses expansions in the body. The closing delimiter must appear by itself.
Fragment
tee copies stdin to stdout and files. tee -a appends rather than replacing the file.
Fragment
The surrounding pipeline still has its own status rules.