3

Why does this script send two emails instead of one?

#!/bin/sh
MONITORDIR="/path/to/directory"
inotifywait -m -r -e create --format '%w%f' "${MONITORDIR}" | while read 
NEWFILE
do
[  -z "${NEWFILE}" ] && : || MOVIE=$(find "$NEWFILE" -type f -not -name ".*" 
\( -iname "*.mkv" -o -iname "*.mp4" -o -iname "*.avi" \) -exec basename {} 
\; | sed 's/\.[^.]*$//')
[  -z "${MOVIE}" ] && : || echo "Please don't reply to this 
automatically generated email message." | mail -s "$MOVIE is now on Plex!" 
"email1@gmail.com,email2@gmail.com"
done
David Custer
  • 621
  • 1
  • 7
  • 11

1 Answers1

2
[  -z "${MOVIE}" ] && : || echo "Please don't reply to this 

Note that A && B || C is not if-then-else. C may run when A is true.

Duc Filan
  • 6,769
  • 3
  • 21
  • 26