【发布时间】:2014-09-07 16:57:40
【问题描述】:
我正在查看 pre-commit 钩子并发现以下行,因为我想知道为什么在提交后我的目录中总是有一个名为 1 的 empy 文件。
git status 2&>1 > /dev/null
我相信我的意图是写以下内容,我更正了它。
git status 2>&1 > /dev/null
但是,我很好奇下面的语法到底是做什么的,所以我查阅了手册页。
git status 2&>1
这是手册页。
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 equiva‐
lent to
>word 2>&1
但是,这个手册页暗示这两者是等价的,但似乎并非如此。
有人可以澄清手册页并准确解释这种语法发生了什么吗?
【问题讨论】:
-
我以为我在某个地方看到了这个问题......也许我错了。
-
符号顺序不同。
-
@devnull,我知道这是一个错字,但我还是想知道它是什么意思。 :)
-
&>与2>&1相同在 bash 中,但在其他 shell 中不一样,例如 dash! -
投票重新打开 - 副本不同(并且
git status 2>&1与git status 2&>1不同)
标签: bash