I want to monitor a given directory until a certain condition arises.
ARCHIVE_PATH=$(inotifywait -m -r -q -e close_write -e moved_to --format '%w%f' /test | while read FILE; do
# ... Code ...
if [ $CONDITION ]; then
echo "$VALUE"
break
fi
done)
Now, no matter whether I use break
or exit 0
, the while loop will continue. What is the best way of exiting the loop and passing the output to the variable, then?
EDIT:
Replacing break
with kill -2 $$
seems to only trigger a continue.
And even worse - there are times, when break works fine - but rarely.