I am trying to make a bash script with inotiy-tools
that will monitor a directory.
Here is my script
while f=$(inotifywait -m -e create -q -r "/media/data2/Music/English" --format '%f %w')
do
echo "$f"
done
The problem is when I run the above script it prints nothing on the terminal. I have checked the inotifywait
command and it runs fine on terminal but why it is not working inside my script.
inotifywait on terminal
noob@noob:~$ inotifywait -m -e create -q -r /media/data2/Music/English --format '%f %w'
hello /media/data2/Music/English/
The problem is f=$(inotifywait...
waits for that command to end and only then gives you the output.
I rarely write bash, but you could try:
inotifywait .... |
while read line
do
echo $line
done