bash - Inotifywait 不运行命令

标签 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

我尝试在执行部分中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/

相关文章:

javascript - 使表格可滚动

linux - 在多线程程序中为 Inotify 添加 watch

macos - 如何 cd 到脚本回显的目录

regex - bash 正则表达式中的匹配组

bash - d=${c//[^$b]} 如何统计字母$b在$c中出现了多少次?

multithreading - Linux::Inotify2 和线程

shell - inotifywait 在将 docx 转换为 PDF 时触发事件两次

javascript - 在样式表中快速切换 rems 和像素

html - 使用手写笔功能时保持手写颜色值

git - 有没有办法在一个命令中使用用户名和密码从 gitlab 克隆?