Andrew Andrew - 6 months ago 18
Bash Question

Send process' STDOUT to screen and second process, but wait for both to finish

This is a sort of branch from this question (specifically avoiding the race condition pointed out by jmb): How can I send the stdout of one process to multiple processes using (preferably unnamed) pipes in Unix (or Windows)?

I want to execute a process in such a way that its output is displayed on the screen plus piped to a second process, but that my terminal is not released until both processes are complete. For example, if I had:

echo "FOO"

read inp
sleep 5
echo "BAR${inp}BAR"

And then ran: | tee >(

I'd like to get the output:

> <--terminal released after bar (total time 5s)

but instead I get:

>BARFOOBAR <--terminal released after foo in ~0s, before returns at 5s

Is there an easy way to do this? The only way I can think of right now is to instead call everything like this: |

and then rewrite such that it continually checks its STDIN and prints this to screen, but this seems like a very inelegant way of solving the problem.

Thanks for the help!


try: | tee /dev/tty |