0

I've had this little script:

#!/bin/bash
echo "every time script $1 is saved, run the script"
while inotifywait -e modify -qq $1; do
  $1 $2
done

which has been so immensely helpful for me when writing scripts (editing file in tmux left pane, having script get executed automatically in tmux right pane) over the last few years. But now...

I have a similar script:

#!/bin/bash
while inotifywait -e modify -qq file.py; do
  python file.py stuff
done

and it just aborts when I save the file. By "abort" I mean that instead of running python file.py stuff and displaying the results it just returns me to the command prompt.

Running the command python file.py stuff works just fine: the file merely prints the first argument supplied to the script, "stuff" in this case. But this inotifywait command keeps aborting.

Why? How to troubleshoot?

man inotifywait gives the following example which is nearly identical to how I'm using it (I'm just passing addition -qq flag):

#!/bin/sh
while inotifywait -e modify /var/log/messages; do
  if tail -n1 /var/log/messages | grep httpd; then
    kdialog --msgbox "Apache needs love!"
  fi
done

Since I'm doing nearly the same thing I don't know why I should try to invoke inotifywait differently as some posts around the web have described (but I've tried several of them anyway without success).

I'm doing this in a tmux environment but I don't know how that could affect this. I'm stumped on what to investigate or how to debug this.

Any ideas?

alec
  • 345
  • 3
  • 14
  • omg the problem seems to correlate with which vimrc file I'm using... that's certainly new information... but *why*... – alec Nov 14 '21 at 22:33

1 Answers1

0

inotifywait -e modify -qq $1 is not aborting, it only returns an error when event is not modify.

Try this :

#!/usr/bin/env bash
inotifywait -e modify -m file.py |\
while read; do
  python file.py stuff
done
Philippe
  • 20,025
  • 2
  • 23
  • 32