Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

Explain file descriptors 0, 1 and 2 and the main redirection operators.

BeginnerConceptArguments, I/O, here-docs, process substitution and subshells
Answer

0 is stdin, 1 is stdout, 2 is stderr.

Syntax Effect
> f / >> f stdout to file (truncate / append)
2> f stderr to file
&> f or > f 2>&1 both to file
2>&1 stderr to wherever stdout points now
< f stdin from file
>&2 this command's stdout to stderr
2>/dev/null discard errors
cmd 2>&1 | tee log both streams to screen and file
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells