(echo foo && sleep 1 && echo bar) | grep -P . | tee /dev/null
The above code is the smallest case of my problem I could come up with. The expected behavior is that foo
would be echo'd, a second would pass, then bar
would be echo'd.
What actually happens is that a second passes then foo
and bar
are echo'd at the same time. If you remove either the grep
or the tee
command (or both, obviously) the correct behavior happens. But with them together it does not.
I assume this is some kind of buffering issue, but I don't know how to get around it. The actual script this is taking place in for me is running for quite a while and I'm not seeing any log messages till the very end. Halp! :(