How should I understand "> outfile 2> & 1" and "2> & 1> outfile"?
I can not understand the difference between these two cases:
./a.out > outfile 2>&I can see both standard output and error output in outfile
./a.out 2>& > outfileI can only see the standard output int outfile, and the error output was printed on the screen
How should I understand that? I think they are the same!
n> filecreates / truncates fileand associates it with a file descriptor n. If nnot specified, it is assumed 1(i.e. standard output).
n>&mcopy (using dup2()) the file descriptor mto n.
, ./a.out 2>& >outfile, stderr, stdout outfile.
, :
2>& >filefd2 := fd1; fd1 := "file",>file 2>&fd1 := "file"; fd2 := fd1