I need to do something similar to this question, except that in that question the OP just concat the outputs of command2 and command3, and I need them be handed over separately, like this:
command2 [stream A]
/ \
command1 join -j1 [stream A] [stream B]
\ /
command3 [stream B]
(here, join is the coreutils join utility, the only one I've named explicitely to make it clear that I don't want the streams A and B to be merged indiscriminately)
I've tried this:
command1 | tee >(command2 >&3- ) >(command3 >&4- ) >/dev/null | join -j1 /dev/fd/3 /dev/fd/4
But bash rightfully complains:
bash: 3: Bad file descriptor
bash: 4: Bad file descriptor
(because file descriptors 3 and 4 are not open yet)
I think I need instruct bash to somehow call 2 extra pipe(2) (like it does when piping fd1 from left command to fd0 of right command in left | right). As each call of such pipe(2) creates two fds (one for writing and other for reading), I need to:
- for
command2close the reading end, and redirect stdout to the writing end (of pipe1); - for
command3close the reading end, and redirect stdout to the writing end (of pipe2); - for
joinclose both writing ends and instruct it to open/dev/fd/reading-end-of-pipe1and/dev/fd/reading-end-of-pipe2
I don't necessarily have write access to any path in this enviroment, precluding the use of mkfifo.