Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does the AND operator '&' do in "& tee"?

In my development environment there exists an alias that writes stdout to a specific file.

It uses pipe with tee, e.g., du -h | & tee /tmp/diskUsage.

I understand that AND operator makes whatever it precedes a file descriptor instead of filename, say by 2>&1 we are redirecting stderr to stdout instead of a file called "1" in current dir.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, for the usage | & tee, there is nothing meaningful after ‘&’ and before "tee", what does it do in this case?

>Solution :

|& is shorthand for "pipe both stderr and stdout from the left hand program to the right hand program".

Basically, tee will receive both normal output and error output muxed together, not just stdout as plain | would do normally.

Or to quote GNU docs:

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 command1.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading