Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command pipe into subshell

Tags:

unix

tee

What is the difference between

cat dat | tee >(wc -l ) | some other command

and

cat dat | tee file | wc -l

in terms of what is happening under the hood? I can understand the second one as tee is forking the stream into a file and also to a pipe. But I am confused with the first one.

like image 515
Alby Avatar asked May 07 '26 00:05

Alby


1 Answers

The first notation is the process substitution of Bash 4.x (not in 3.x, or not all versions of 3.x).

As far as tee is concerned, it is given a file name (such as /dev/fd/64) to which it writes as well as to standard output; it is actually a file descriptor for the write end of a pipe. As far as wc is concerned, it reads its standard input (which is the read end of the pipe that is connected to /dev/fd/64 for tee), and writes its answer to the standard output of the shell invoking the pipeline (not the standard output of tee which goes down the pipeline).

like image 50
Jonathan Leffler Avatar answered May 11 '26 16:05

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!