“&>>”在bash中有什么用?

Aks*_*til 5 shell bash io-redirection

我正在研究一个 bash 脚本代码,在那里我遇到了运算符“&>>”。我不明白它的用途。所以,我提到了http://www.gnu.org/software/bash/manual/html_node/Redirections.html

它在语义上等同于>> file 2>&1.

以下是我的 shell 的输出:-

# echo $SHELL
/bin/bash
# echo "hello" &>> file1
bash: syntax error near unexpected token `>'
Run Code Online (Sandbox Code Playgroud)

# echo "hello" >> file1 2>&1

# cat file1 

hello
Run Code Online (Sandbox Code Playgroud)

问题:- 为什么我收到错误bash: syntax error near unexpected token '>'

[编辑] :- Bash 版本 3.2.25(1)-release (x86_64-redhat-linux-gnu)

Rad*_*anu 4

您收到该错误是因为您使用旧版本的 bash (3.2.25)。

从 Bash4 开始,就有&>>TARGET,相当于>> TARGET 2>&1.

来源:附加重定向输出

因此,您应该考虑升级。我使用 bash 版本 4.2.45,echo "hello" &>> file1它对我来说就像一个魅力。