1

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 の man ページを確認したところ、次のように表示されました。

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 ).

しかし、言ったように、端末に何もリストされていません。「現在のイベントの影響を受けるパス」を表示する方法を知っている人はいますか?

すべてのヒントは大歓迎です!

4

1 に答える 1

3

もちろん、これを使用してください:

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
于 2016-02-14T19:17:06.583 に答える