Hello!
When I use a pipe and the receiving end dies, I understand that the
sending end is terminated. But when I use stdbuf on the sender, a dying
receiving does not terminate the pipe. Example:
$ { i=0; while true; do echo "send $i" >&2; echo $((i++)); sleep 1;
done; } | { while read s; [[ $s != 5 ]]; do echo "receive $s"; done; }
send 0
receive 0
send 1
receive 1
send 2
receive 2
send 3
receive 3
send 4
receive 4
send 5
send 6
$ { i=0; while true; do echo "send $i" >&2; stdbuf -oL echo $((i++));
sleep 1; done; } | { while read s; [[ $s != 5 ]]; do echo "receive $s";
done; }
send 0
receive 0
send 1
receive 1
send 2
receive 2
send 3
receive 3
send 4
receive 4
send 5
send 6
send 7
send 8
... [manually killed by CTRL-C]
Could anyone explain the reason for this behaviour to me?
Kindest regards,
Paul