Inotifywait不运行命令

时间:2012-09-06 21:36:12

标签: bash inotify stylus

我有一个名为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

我尝试在exec部分中使用echo "hi"但没有执行

2 个答案:

答案 0 :(得分:4)

您遇到的问题是-m的{​​{1}}选项。这会导致命令永不退出。由于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

答案 1 :(得分:0)

试试这个:

while K=`inotifywait -o ./log.txt --format %f -e modify ./*.styl`; 
do 
   stylus -c $K;
done
相关问题