The operators we are using here are:
>Syntax: file_descriptoropt>file_name>&Syntax: file_descriptoropt>&file_descriptor&>Syntax:&>file_name
If the file descriptor is omitted, the default is 0 (stdin) for input, or 1 (stdout) for output. 2 means stderr.
So we have:
>namemeans1>name— redirect stdout to the filename&>nameis like1>name 2>name— redirect stdout and stderr to the filename(howevernameis only opened once; if you actually wrote1>name 2>nameit’d try to opennametwice and perhaps malfunction).
So when you write git status 2&>1, it is therefore like git status 2 1>1 2>1 , i.e.
- the first
2actually gets passed as an argument togit status. - stdout is redirected to the file named
1(not the file descriptor 1) - stderr is redirected to the file named
1
This command should actually create a file called 1 with the contents being the result of git status 2 — i.e. the status of the file called 2 which is probably “Your branch is upto-date, nothing to commit, working directory clean”, presuming you do not actually track a file called 2.