I know 0 , 1, 2 are STDIN , STDOUT and STDERR file descriptors.
I am trying to understand redirection.
‘>’ means dump to a file
‘>>’ means append
But what does ‘>&’ do ?
Also what is the step by step process for the following commands ?
command > file 2>&1
command > file 2<&1
NUMBER1>&NUMBER2means to assign the file descriptor NUMBER2 the file descriptor NUMBER1.That means, to execute
dup2 (NUMBER2, NUMBER1).Bash process the command line, it finds first the redirection
>file, it changes stdout to be written tofile, then continue to process and finds2>&1, and changes stderr to be written to stdout (which isfilein this moment) .this is the same, but
2<&1redirects stderr toreadfrom stdout. Because nobody reads from stderr, this second redirection normally has no effect.However, bash treats this special case doing the same as for
2>&1, so executingdup2 (1, 2).What does "2<&1" redirect do in Bourne shell?