似乎有两个 bash 习语用于将 STDOUT 和 STDERR 重定向到文件:
fooscript &> foo
...和...
fooscript > foo 2>&1
有什么区别?在我看来,第一个只是第二个的快捷方式,但我的同事争辩说,即使初始重定向出现错误,第二个也不会产生任何输出,而第一个会将重定向错误吐到 STDOUT。
编辑:好的...似乎人们不明白我在问什么,所以我会尝试澄清:
谁能给我一个例子,上面写的两行特定行会产生不同的行为?
最佳答案
来自bash manual :
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
短语“语义等价”应该可以解决您与同事的问题。
关于bash - "&> foo"和 "> foo 2>&1"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/188208/