当文件更改时,我使用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.但我也想知道到底是哪个文件导致了这一行动。因此,我检查了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 ).但如前所述,我在航站楼上没有看到任何东西。有人知道我如何显示“受当前事件影响的路径”吗?
欢迎所有小费!
发布于 2016-02-14 19:17:06
当然,用这个:
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
donehttps://stackoverflow.com/questions/35395699
复制相似问题