Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

429
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda