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

后端 未结 6 1472
慢半拍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:10

    From info bash:

    3.6.7 Duplicating File Descriptors
    ----------------------------------
    
    The redirection operator
         [N]<&WORD
       is used to duplicate input file descriptors.  If WORD expands to one
    or more digits, the file descriptor denoted by N is made to be a copy
    of that file descriptor.  If the digits in WORD do not specify a file
    descriptor open for input, a redirection error occurs.  If WORD
    evaluates to `-', file descriptor N is closed.  If N is not specified,
    the standard input (file descriptor 0) is used.
    
       The operator
         [N]>&WORD
       is used similarly to duplicate output file descriptors.  If N is not
    specified, the standard output (file descriptor 1) is used.  If the
    digits in WORD do not specify a file descriptor open for output, a
    redirection error occurs.  As a special case, if N is omitted, and WORD
    does not expand to one or more digits, the standard output and standard
    error are redirected as described previously.
    

    So 2>&1 duplicates fd 1 onto fd 2.

提交回复
热议问题