ar- / incron

cron-like daemon which handles filesystem events
Other
229 stars 51 forks source link

Why do I have #<number> when $# is passed as an argument to a command in incrontab? #47

Closed doronbehar closed 6 years ago

doronbehar commented 6 years ago

I'm trying to write a simple script that will take $# as an argument whenever a file is modified or created in a certain directory but I'm experiencing a very weird and inconsistent issue. I'll explain.

Let's put the following in incrontab:

$HOME/incron-test   IN_MODIFY,IN_CREATE $HOME/incron-test.sh "$#"

Let's put a file with tricky characters like ( and ) a very long name.txt inside ~/incron-test. As far as I understand so far and after some experiments, I realized I need to quote $# because otherwise ~/incron-test.sh won't understand it receives a single argument, correct me if I'm wrong so far.

Inside ~/incron-test.sh, put the following:

echo "$@" > ~/incron-test.log

There should be no problem with this test.

I'm trying to perform the exact same setup only with a different directory - /var/lib/mpd/playlists. As you may have guessed, this is the where all of mpd's playlists are saved. The problem appears when I edit a playlist from a client like ncmpcpp. Here is incrond's journal when I do so:

Apr 30 22:05:23 NUC incrond[404]: PATH (/var/lib/mpd/playlists) FILE (#6946859) EVENT (IN_MODIFY)
Apr 30 22:05:23 NUC incrond[404]: (doron) CMD (/home/doron/.local/share/playlists/import.sh "#6946859")
Apr 30 22:05:23 NUC incrond[404]: PATH (/var/lib/mpd/playlists) FILE (Fabolus\ Seekers.m3u) EVENT (IN_CREATE)

What is #6946859? The playlist file I've edited in this test was Fabolus\ Seekers.m3u.

doronbehar commented 6 years ago

I think this is an issue of the way ncmpcpp edits the playlists and it is unrelated to incron's behavior.