4

Thanks in advance for any advice

I'm working on an fswatch command to launch a script when files hit the Downloads folder.

fswatch --event Created Downloads/ | (while read x; do echo $x | xargs -0 bash ./dlsort.sh; done)

The script is working as intended. The issue I'm having is (I expect) coming from the (while read x; bit:

The problem is that dlsort.sh is getting called twice for each download. Since the first run of the script moves the file, I'm getting a "No such file or directory" error on the second run. It's not a big deal, since the file makes it where it's supposed to go, but I'm mostly working on this project to teach myself more about bash/scripting, so I'd like to figure out what I'm misunderstanding about this command.

EDIT: adding dlsort.sh

if (echo "$1" | grep -q '\.jpg$'); then
  mv "$1" Desktop/targdir/
else
  mv "$1" Downloads/
fi

0 Answers0