There is excelent article from Brian Storti back from 2015 about shell script’s idiom 2>&1
So to note important points
File descriptors are positive integer number that uniquely represents an opened file in operating system.
Recap of I/O redirection
There are two places programs send output to: Standard output (stdout) and Standard Error (stderr);
- You can redirect these outputs to a different place (like a file);
- File descriptors are used to identify
command > outputis just a shortcut for
command 1> output;
- You can use &[FILE_DESCRIPTOR] to reference a file descriptor value;
2>&1will redirect stderr to whatever value is set to stdout (and
1>&2will do the opposite).