inotifywait 不将输出管道输出到控制台

inotifywait not piping output to console

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

脚本:

#!/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

我有两个问题:

为什么修改的事件被注册了两次?我只更新了一次文件。 为什么 "test" 没有打印到我是 运行 脚本的控制台?

我遇到了类似的问题。我通过重组 while:

解决了第二部分
inotifywait -e modify -r -m ./ --exclude '\.sh$' |
while read E; do                      
  echo "----------------hello $E"               
done