Redirect or Pipe Output from One Command to Many
There are a few possible solutions that range from pretty straight forward to a little tricky.
Process Substitution
If you know you'll always be running under a shell that supports process substitution(bash
, zsh
, ksh93
) multiplexing a command's output is pretty easy using tee
. tee
supports outputting to multiple "files" and with process redirection those "files" can be other commands.
# Output to two other commands, and STDOUT
tee >(commandA) >(commandB)
# Output to three commands, all captured and redirected to commandC
tee >(commandA) >(commandB) | commandC
Note in the second example that commandC
is going to see the output from whatever output tee
(i.e. whatever output was piped to tee
), commandA
and commandB
each produced. So, if grep
is your commandC
you'll search the output from all three proceeding commands.
File Descriptors
If your shell uses /dev
file descriptors (i.e. POSIX, e.g. /dev/3
).
{ { { tee /dev/fd3 /dev/fd4 | commandFD1 >&5; }
3>&1 | commandFD3 >&5; }
4>&1 | commandFD4 >&5;
} > 5>&1