我有一个名为 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”
,但没有执行任何内容
最佳答案
您遇到的问题是 inotifywait
的 -m
选项。这会导致命令永远不会退出。由于 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
关于bash - Inotifywait 不运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12308761/