I hope this is not too late.
What is happening is that some of the patterns are not being match to a particular file, so they are being passed 'as is' to the mv command. This is also happens on the ls command. For example:
Code:
$ ls *.gify
ls: cannot access *.gify: No such file or directory
$ mv *.gify ./tmp
mv: cannot stat `*.gify': No such file or directory
That is the expected behavior of bash as an interactive shell. In scripts the default can be change, so that the not matching expression is expanded as a null string. For that use this in your script:
Now in the case of a custom message for each copied file, you would have to copy one file at a time, so you can learn the result of the command mv. This is an example:
Code:
#!/bin/bash
# List of patterns.
FILES='*.jpg *.JPG *.jpeg *.JPEG *.bmp *.BMP *.png *.PNG *.gif *.GIF'
# Destination directory
DIR=./tmp
# Exapand non maching patterns to null.
shopt -s nullglob
for file in $FILES; do
mv "$file" "$DIR" &> /dev/null
if [ $? = 0 ]; then
echo "$file was found and moved to $DIR."
else
echo "Unable to move $file to $DIR."
fi
done
Hope it helps.
Bookmarks