Why does this simple email script sends two emails every time

125 views Asked by At

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!" 
"[email protected],[email protected]"
done
1

There are 1 answers

0
Duc Filan On
[  -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.