If you are dealing with many files, you can also use GLOBIGNOREor extended globbingto avoid expanding the files you want to skip in the first place (which can be faster):
GLOBIGNORE='zz*'
for file in *.JPG; do
do_something_with "${file}"
done
or
shopt -s extglob
for file in !(zz*).JPG; do
do_something_with "${file}"
done
shopt -u extglob
, .JPG, , $i *.JPG ( ), , nullglob.
for file in *.JPG; do
[ -e "${file}" ] || continue
do_something_with "${file}"
done
shopt -s nullglob
for file *.JPG; do
do_something_with "${file}"
done
shopt -u nullglob
, , nullglob:
$ for f in *.doesnotexist; do echo "$f"; done
*.doesnotexist