79

For example

echo "aaa" |& cat

What does |& mean here?

Is there a website recommended to look up those? Since most search engines can't support searching special characters.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Nan Hua
  • 2,974
  • 3
  • 14
  • 22
  • 1
    FYI: `echo "aaa" |& cat` may lead to `-bash: syntax error near unexpected token \`&'` if `bash --version` is `GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)`. – pmor Feb 17 '22 at 23:34

3 Answers3

74

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.

Oleg Andriyanov
  • 4,797
  • 1
  • 19
  • 33
  • 2
    @BallpointBen exactly. From https://www.gnu.org/software/bash/manual/bash.pdf: `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 |.` – SantaXL Nov 18 '19 at 16:22
16

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.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
lunaryorn
  • 32,410
  • 7
  • 74
  • 89
2

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.

honzajde
  • 2,053
  • 3
  • 26
  • 35