I pipe the same content to multiple commands with tee, subshells and redirects like this:#!/usr/bin/env bashecho 'hello' | tee \  >( sleep 3; cat /dev/stdin ) \  >( sleep 2; cat /dev/stdin ) \  >( sleep 1; cat /dev/stdin )wait # Doesn't work :(However, what I see is that the subshell output is written to the terminal after the main script exits and wait doesn't work:$ ./test.shhello$ hellohellohelloHow to properly wait for the subshells?
Wait for Bash subshells
bash;shell script;background process;process substitution
In bash, you can't wait for process substitution. In:cmd1 > >(cmd2)the whole command finish as soon as cmd1 finish, regardless the status of cmd2.You have to implement a mechanism to signal the parent process that the cmd2 have finished. An easy way, using a fifo:#!/usr/bin/env bashtrap 'rm wait.fifo' EXITmkfifo wait.fifoecho 'hello' | tee \  >( sleep 3; cat /dev/stdin; : >wait.fifo ) \  >( sleep 2; cat /dev/stdin; : >wait.fifo ) \  >( sleep 1; cat /dev/stdin; : >wait.fifo )for (( i=0;i<3;i++ )); do read <wait.fifo; done