I intend to pipe the output of a program into a while read VAR
loop and break
when a pattern is found, but it doesn't.
Proof of concept:
inotifywait -qm -e create . | while read line; do echo $line; break; done
./ CREATE newfile
..
tail -f /var/log/syslog | while read line; do echo $line; break; done
Nov 6 22:44:05 section9 ntpdate[2381]: adjust time server 91.189.89.199 offset 0.272779 sec
These never exit no matter what the source program outputs. Setting set -x
beforehand suggests that the loop never iterates to the second read
. $BASH_SUBSHELL
is 1 in these examples.
Shouldn't tail
, inotifywait
, etc. receive SIGPIPE and exit?
Note that process substitution (while read ... break; done < <(tail -f ...)
) works OK. $BASH_SUBSHELL
is 0 in this case.