Reputation: 5742
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.
Upvotes: 3
Views: 2140
Reputation: 753725
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).
Upvotes: 3
Reputation: 1243
Since >( is process substitiution of bash, the first line says: send the contents of file 'dat' into some other command while process 'wc' is run with its input or output connected to a pipe which also sends the content of 'dat'
check "Process Substitution" of bash manpage.
Upvotes: 1