“ | &”在 Bash 中是什么意思?

比如说

echo "aaa" |& cat

|&在这里是什么意思?

有没有推荐的网站来查找这些信息? 因为大多数搜索引擎不支持搜索特殊字符。

21633 次浏览

From man 1 bash, section Pipelines:

[time [-p]] [ ! ] command [ [|⎪|&] command2 ... ]

If |& is used, command's standard error, in addition to its standard output, is connected to command2's standard input through the pipe

So it is just like the pipe operator |, but piping both standard output and standard error.

This operator pipes both standard output and standard error from the left hand side to the right hand side.

The Bash reference manual has a comprehensive index of all operators where you can look up these operators.

If ‘|&’ is used, command1’s standard error, in addition to its standard output, is connected to command2’s standard input through the pipe; it is shorthand for 2>&1 |. This implicit redirection of the standard error to the standard output is performed after any redirections specified by the command.

command1 |& command2 equal command1 2>&1 | command2