Search code examples
unixtee

command pipe into subshell


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.


Solution

  • 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).