I want to update a global variable "VARIABLE" within a while loop. As far I understand from other questions, I need to change my code in such a way that while loop is not a separate subprocess. To make it happen, I changed:
VARIABLE=1
/usr/bin/inotifywait --monitor --quiet -e moved_to -e close_write --format '%w%f' "$CACHE_DIR" | while read -r INPUT_FILE
do
VARIABLE=42
done
to:
VARIABLE=1
while read -r INPUT_FILE
do
VARIABLE=42
done <<< "$(/usr/bin/inotifywait --monitor --quiet -e moved_to -e close_write --format '%w%f' "$CACHE_DIR")"
However, it seems that now inotifywait never notifies about events, but it worked fine before. What is wrong? If for whatever reason my approach is not suitable for inotifywait, are there any alternatives?