echo foo | tee >(echo $$) >(echo $$) >/dev/null | cat

returns the same PID twice. I'm using the version 4.4.11.
Why is there only one process for all the expansions?
Why wasn't that documented?

I think the only right way to do multiple process expansions in one command
is by actually _starting one process for each expansion_.

Why doesn't this workaround work? It produces the same output as the first snippet
echo foo | tee >((echo $$)) >((echo $$)) >/dev/null | cat

You might now be wondering why I'm saying that it is wrong to
execute everything in one process. Consider the following:

cat some file | tee \
    >(mutex --lock; critical; mutex --unlock) \
    >(mutex --lock; critical; mutex --unlock) \
    > /dev/null | cat

What I'd wish for is that both >() blocks get the same input by tee and produce some synchronized output.
That is also the most natural way to think about this expansion.
GNU parallel allows for something like mutex --lock by the way.

There are problems that'd require for something like the above.

Reply via email to