Sunday, May 12, 2024
22
rated 0 times [  22] [ 0]  / answers: 1 / hits: 29892  / 2 Years ago, wed, august 17, 2022, 11:24:47

So I'm doing a simple inotifywait loop to watch for changes in a Bootstrap directory:



while inotifywait -r -q --format %w bootstrap/; do
echo "something happened"
[[ $filename == *.js ]] && uglifyjs .....
[[ $filename == *.less ]] && lessc bootstrap.less
done


You don't really need to worry about the internals but I just can't get the filename back into a bash scope. inotifywait echos out the filename (with help from the format argument) but how do I capture that and use it later on (in my case, as $filename)?






If you want a simple, short test harness:



touch testfile
while inotifywait testfile do; echo "..."; done


And then you can just run touch testfile when you want to trigger it.


More From » command-line

 Answers
7

The cleaner way is illustrated in this blog entry:



inotifywait -m -r -q --format '%w' bootstrap/ | while read FILE
do
echo "something happened on path $FILE"
done

[#28147] Friday, August 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
socelebrate

Total Points: 274
Total Questions: 123
Total Answers: 124

Location: Saint Helena
Member since Mon, Jan 16, 2023
1 Year ago
;