Way to pipe the output of one program into two other programs

pipe

Sorry if this is a silly question but I'm trying to accomplish something like this but on one line:

$ prog1 | prog2
$ prog1 | prog3

So, I basically want to execute prog1 and pipe the output to prog2 and prog3 separately (not a chained pipe). At first, I was trying to use tee but that didn't seem right because it was dumping output to a file (which is not what I want).

$ prog1 | tee prog2 | prog3 # doesn't work - creates file "prog2"

At some point, I'd probably want to extend this to piping the output to more than two programs but I'm just starting simple for now.

$ prog1 | prog2
$ prog1 | prog3
$ prog1 | prog4
...

Best Answer

Process substitution.

... | tee >(prog2) | ...
Related Question