1

我有以下运行 inotifywait 命令的 shell 脚本。我想在每次修改事件时将输出回显打印到控制台。

剧本:

#!/bin/sh
while inotifywait -e modify -r -m ./ --exclude '\.sh$'; do
  echo test
done

当我更改指定目录中的一个文件时,我从 inotifywait 获得标准输出:

Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
./postgres/ MODIFY postgres_test.go
./postgres/ MODIFY postgres_test.go

我有两个问题:

为什么修改的事件注册了两次?我只更新了一次文件。为什么“测试”没有打印到我正在运行脚本的控制台?

4

1 回答 1

2

我有一个类似的问题。我通过重组我的解决了第二部分while

inotifywait -e modify -r -m ./ --exclude '\.sh$' |
while read E; do                      
  echo "----------------hello $E"               
done                                  
于 2020-07-27T03:10:39.737 回答