Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

428
Visualizações
How to print file path that caused fswatch to do something

I use fswatch to take some actions when a file changes. I use the following command:

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

this works fine, if I change a couple files I see the following in the terminal:

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

But I also wonder which file actually caused the action. So I checked the fswatch man page, which shows the following:

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

But as said I don't see anything listed in my terminal. Does anybody know how I can show "The path affected by the current event."?

All tips are welcome!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Sure, use this:

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

If you want to save the names of the affected files in a list, you can do that like this:

#!/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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda