There seem to be at least 2 problems here. When removing sleep 1
from the loop, the code hangs infinitely, probably due to a race condition. Whether the COPROC
never returns, or the redirection
not being closed, I cannot tell. In addition to that, the while
counter loop blocks progress in the main thread. Expectation would be, that '# do things' is being executed, while the loop executes asynchronously, and both threads are being joined (wait $PBAR_PID
) after '# do things'.