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: adjust time server 18.104.22.168 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
$BASH_SUBSHELL is 1 in these examples.
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.