I am trying to set up a script that will loop over a set of directories, and do one thing when it finds .jpg files, and another when it finds .nef files. The problem is, if a directory does not have .jpg files for example (or .nef) then the glob entry is no longer an expanded glob, but just a string. For example:
my_dir="pictures/"
ext="JPG"
for f in "$my_dir"*."$ext"; do
echo $f
done
if the my_dir folder has .JPG files in it, then they will be echoed correctly on the command line.
pictures/one.JPG
pictures/two.JPG
However, if my_dir has no .JPG files, then the loop will enter for one iteration and echo:
pictures/*.JPG
how do I construct this so that if the glob has no matches, it does not enter the for loop?