Quote:
Originally Posted by
Ditto
Changed my code to this (added the exec), and now it works
This is what has been happening in your original code ...
When tee opens the fifo for reading, if no other process has yet written to the fifo, tee will block (hang/sleep) until another process opens the fifo and writes to it.
Each echo statement will attempt to open the fifo, write to it, and then close it. Most likely, when this succeeds, it is because both echoes have written to the fifo before tee has a chance to read it.
Adding
ls greatly increases the chances of tee reading between the echoes. If that happens, after reading the first echo's text, tee will detect EOF and exit. When the second echo opens the fifo for writing, it will hang until something opens the fifo for reading (which will never happen with your sample script).
exec 5>fifo prevents the hang by ensuring that there is always a write file descriptor for the fifo. That descriptor is never used, but since it has permission to write, so long as it exists, tee will not read EOF; instead, tee will block until someone writes (in this case, the second echo).
Regards,
Alister