How do pipes and redirection work?
Every process has three standard streams: stdin (0), stdout (1) and stderr (2). Redirection connects them to files or other processes.
cmd > out.log # stdout to file, truncate
cmd >> out.log # append
cmd 2> err.log # stderr only
cmd > all.log 2>&1 # both, order matters
cmd &> all.log # bash shorthand
cmd < input.txt # stdin from file
cmd | tee out.log # pipe and also write a file
A pipe connects the stdout of the left command to the stdin of the right and runs both concurrently. The exit status of a pipeline is the last command's unless pipefail is set.
Order matters in > all.log 2>&1: the file descriptor 2 is pointed at wherever 1 currently points, so redirect stdout first. <<< is a here-string, <<EOF a here-document, and |& pipes both streams. Process substitution such as <(cmd) presents command output as a file.