gpt4 book ai didi

bash ->& 是什么意思?

转载 作者:行者123 更新时间:2023-11-29 08:39:43 26 4
gpt4 key购买 nike

我对这个表达有点困惑:

gcc -c -g program.c >& compiler.txt

我知道 &>filename 会将 stdout 和 stderr 重定向到文件 filename。但在这种情况下,& 符号位于大于号之后。它看起来像是 M>&N 的形式,其中 MN 是文件描述符。

在上面的代码片段中,M=1N='compiler.txt'?这与以下内容有何不同:

gcc -c -g program.c > compiler.txt     (ampersand removed)

我的理解是每个打开的文件都与一个大于 2 的文件描述符相关联。这是正确的吗?

如果是这样,作为重定向目标的文件名是否可以与其文件描述符互换?

最佳答案

这与 &> 相同。来自 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 equiva-
lent to

>word 2>&1

关于bash ->& 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11255447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com