gpt4 book ai didi

linux - 如何打印导致 fswatch 执行某些操作的文件路径

转载 作者:太空宇宙 更新时间:2023-11-04 09:26:56 25 4
gpt4 key购买 nike

我使用 fswatch在文件更改时采取一些操作。我使用以下命令:

fswatch -o -r '.' | while read MODFILE
do
echo 'Some file changed, so take some action'
done

这工作正常,如果我更改几个文件,我会在终端中看到以下内容:

Some file changed, so take some action
Some file changed, so take some action
Some file changed, so take some action
etc.

但我也想知道到底是哪个文件引起了这个 Action 。所以我查看了 fswatch 手册页,其中显示了以下内容:

fswatch writes a record for each event it receives containing:
- The timestamp when the event was received (optionally).
- The path affected by the current event.
- A space-separated list of event types (see EVENT TYPES ).

但如前所述,我没有在我的终端中看到任何列出的内容。有谁知道我如何显示“受当前事件影响的路径。”?

欢迎所有提示!

最佳答案

当然,使用这个:

fswatch --batch-marker=EOF -xn . | while read file event; do 
echo $file $event
if [ $file = "EOF" ]; then
echo TRIGGER
fi
done

如果您想将受影响文件的名称保存在列表中,您可以这样做:

#!/bin/bash
fswatch --batch-marker=EOF -xn . | while read file event; do
if [ $file = "EOF" ]; then
echo TRIGGER
echo Files: "${list[@]}"
list=()
else
echo $file $event
list+=($file)
fi
done

关于linux - 如何打印导致 fswatch 执行某些操作的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35395699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com