在 bash 中捕获 inotifywait 的输出

Capture output of inotifywait in bash

如何在这种情况下捕获 inotifywait 的输出,这让我抓狂。

这是我的代码:

 while inotifywait -q -e  create,delete --format '%T %:e "%f"' --timefmt '%d/%m/%y %H:%M'  "$DIR"
    do
       echo -e "$line" >> /mnt/pidrive1/Digital_Signage/log/"$hostname"_sync.log
       echo -e "Folder contents:" $file_number "files in total: " $folder_list  >> /mnt/pidrive1/Digital_Signage/log/"$hostname"_sync.log
    done

一个更简单的方法来实现你想要的是:

while inotifywait <whaveter> >> sync.log
do
   # Nothing
done

如果您需要对输出做额外的事情,您可以说:

while out=$(inotifywait <whaveter>)
do
    # Stuff
    # Just use $out normally
done