What does the ampersand indicate in this bash command 1>&2

后端 未结 6 1473
慢半拍i
慢半拍i 2020-12-23 16:43

Quick one, 2>&1 redirects stderr to stdout, but what does the ampersand mean? I know if we had 2 > 1 it would output to a file named

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 17:08

    2>&1 redirects standard error (file handle 2) to the same file that standard output (file handle 1) is currently going to.

    It's also a position-dependent thing so:

    prog >x 2>&1 >y
    

    will actually send standard error to x and standard output to y as follows:

    • Connect standard output to x;
    • Then connect standard error to same as current standard output, which is x;
    • Then connect standard output to y;

提交回复
热议问题