2

我有一个名为 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 部分中,但没有执行

4

2 回答 2

4

您遇到的问题-minotifywait. 这会导致命令永远不会退出。由于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
于 2012-09-06T21:48:43.180 回答
0

尝试这个:

while K=`inotifywait -o ./log.txt --format %f -e modify ./*.styl`; 
do 
   stylus -c $K;
done
于 2014-10-20T14:02:49.233 回答