Wrote a script to monitor folders with exclude option with inotifywait and trapped into problem with substitution in command. Script:
exc="/data/local/tmp/1/|/data/local/tmp/2/"
mkdir -p $p1/1 $p1/2
#set -f #globbing off, no changes with this flag
#here i add * to end of each folder
[ "$exc" ] && exc="--exclude '$(sed 's@/|@/*|@g; s@/$@/*@' <<<"$exc")'"
#echo "$exc"
#Modify for test file
(sleep 2
:> /data/local/tmp/1/1.txt)&
#set -x #to watch what will happen
#echo inotifywait -t 10 -r -e modify $exc "$p1" #2>&-
#Working variant
#eval $(echo inotifywait -t 10 -r -e modify $exc "$p1")
#Not working variant
inotifywait -t 10 -r -e modify $exc "$p1"
#set +x #set back
The same code not working directly but works with crutch with eval $(echo) Made the script more simple and optimized so it can be tested easy At start i thought that the problem is in globbing but desabling it makes no difference, so i tested with set -x and noticed some strange things with single quotes. As we can see in second variant inotify false triggered in excluded folder, in eval variant all is ok. Output of variants:
/ # r1
Setting up watches. Beware: since -r was given, this may take a while!Watches established.
/data/local/tmp/1/ MODIFY 1.txt
[1]+ Done ( sleep 2; : > /data/local/tmp/1/1.txt )
/ # r1
Setting up watches. Beware: since -r was given, this may take a while!Watches established.
[1]+ Done ( sleep 2; : > /data/local/tmp/1/1.txt )
Output with set -x flag
/ # r1
++ inotifywait -t 10 -r -e modify --exclude ''\''/data/local/tmp/1/*|/data/local/tmp/2/*'\''' /data/local/tmp
Setting up watches. Beware: since -r was given, this may take a while!Watches established.
/data/local/tmp/1/ MODIFY 1.txt
[1]+ Done ( sleep 2; : > /data/local/tmp/1/1.txt )
++ set +x
/ # r1
+++ echo inotifywait -t 10 -r -e modify --exclude ''\''/data/local/tmp/1/*|/data/local/tmp/2/*'\''' /data/local/tmp
++ eval inotifywait -t 10 -r -e modify --exclude ''\''/data/local/tmp/1/*|/data/local/tmp/2/*'\''' /data/local/tmp
+++ inotifywait -t 10 -r -e modify --exclude '/data/local/tmp/1/*|/data/local/tmp/2/*' /data/local/tmp
Setting up watches. Beware: since -r was given, this may take a while!Watches established.
[1]+ Done ( sleep 2; : > /data/local/tmp/1/1.txt )
++ set +x
Running inotifywait --version : 3.22.6.0