我有一个名为 watch.sh 的基本 inotifywait 脚本和一些以 .styl 结尾的文件,位于同一目录中。这是脚本,它捕获更改,但不执行 do/done 中的代码
我喜欢它sh watch.sh
,这是脚本
#!/bin/sh
while inotifywait -m -o ./log.txt -e modify ./*.styl; do
stylus -c %f
done
我尝试echo "hi"
在 exec 部分中,但没有执行
您遇到的问题-m
是inotifywait
. 这会导致命令永远不会退出。由于while
检查命令的退出状态,命令必须退出才能继续执行循环。
以下是-m
手册页中的描述:
Instead of exiting after receiving a single event, execute
indefinitely. The default behaviour is to exit after the first
event occurs.
删除该-m
选项应该可以解决您的问题:
while inotifywait -o ./log.txt -e modify ./*.styl; do
stylus -c %f
done
尝试这个:
while K=`inotifywait -o ./log.txt --format %f -e modify ./*.styl`;
do
stylus -c $K;
done