Uso fswatch para realizar algunas acciones cuando cambia un archivo. Yo uso el siguiente comando:
fswatch -o -r '.' | while read MODFILE do echo 'Some file changed, so take some action' doneesto funciona bien, si cambio un par de archivos, veo lo siguiente en la terminal:
Some file changed, so take some action Some file changed, so take some action Some file changed, so take some action etc.Pero también me pregunto qué archivo realmente causó la acción. Así que revisé la página de manual de fswatch, que muestra lo siguiente:
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 ).Pero como dije, no veo nada en mi terminal. ¿Alguien sabe cómo puedo mostrar " La ruta afectada por el evento actual". ?
¡Todos los consejos son bienvenidos!
Claro, usa esto:
fswatch --batch-marker=EOF -xn . | while read file event; do echo $file $event if [ $file = "EOF" ]; then echo TRIGGER fi doneSi desea guardar los nombres de los archivos afectados en una lista, puede hacerlo así:
#!/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