I am having an issue with exiting a bash script out of a while loop:
while read -r dir event name; do
case $event in
OPEN)
chown $VHOST:$VHOST $WEBPATH/$name;
echo "The file \"$name\" was created (not necessarily writable)";
;;
WRITE)
echo "The file \"$name\" was written to";
;;
DELETE)
echo "The file \"$name\" was deleted";
exit 0;
;;
esac
done < <(/usr/bin/inotifywait -m $WEBPATH)
The loop correctly listens for file changes in the given Directory, so far so good.
This also shows on the console output:
root #: bash /var/scriptusr/letsencrypt/dir-change
Setting up watches.
Watches established.
The file "tes" was created (not necessarily writable)
The file "tes" was deleted
root #:
Apparently it seems the script exited nicely but when you search for it in the process tree it is still there:
root #: ps aux | grep dir-
root 5549 0.0 0.0 14700 1716 pts/0 S 14:46 0:00 bash /var/scriptusr/letsencrypt/dir-change
root 5558 0.0 0.0 14184 2184 pts/1 S+ 14:46 0:00 grep dir-
root #:
So my question is how to really exit the script?