Answers:
这&>
,不仅是&
。
在中bash
,&>
将标准输出流和标准错误流都重定向到某处。
因此,utility &>/dev/null
与相同utility >/dev/null 2>&1
。
该命令exec &>/dev/null
将当前shell的两个输出流重定向到/dev/null
(即,从该点开始,无论是否出错,都将丢弃脚本的所有输出)。
bash
手册的相关部分:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard
error:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically
equivalent to
>word 2>&1
When using the second form, word may not expand to a number or -. If
it does, other redirection operators apply (see Duplicating File
Descriptors below) for compatibility reasons.
exec 2>&1 > /dev/null
/dev/null
(但不是标准错误)。等效于exec >/dev/null 2>&1
。重定向的顺序很重要。