bashglob

Glob different file extension in bash script for loop


I can't spot the error here, why is it not globbing but using ls *.{jpg,JPEG,JPG,jpeg,PNG,png} it runs perfectly?

How to fix it?

for file in *.{jpg,JPEG,JPG,jpeg,PNG,png}
  do
echo $file
  #convert "${file}" -scale 50% gallery_"${file}".jpg
done

Solution

  • Enable nullglob to avoid unexpanded globs:

    shopt -s nullglob