How to iterate through multiple file extension without caring about case sensitivity

command linescriptterminal

I've seen various topics on how to iterate through multiple file extensions, but in most cases the list is defined.

example:

for file in ${arg}/**/*.{txt,h,py}
do
    ....
done

As can be seen, .TXT files would be ignored. And sadly, the guy who answered it says it only works for bash4. Mavericks is using bash 3.x

Any ideas on how it can be done on OS X?

Best Answer

Use find:

find "$arg" -iname \*.txt -o -iname \*.h -o -iname \*.py|while read f;do :;done

Use IFS= read -r if the paths can end with spaces or contain backslashes.

Or install bash 4:

brew install bash;echo /usr/local/bin/bash|sudo tee -a /etc/shells;chsh -s /usr/local/bin/bash

Then:

 shopt -s globstar nocaseglob;for f in "$arg"/**/*.{txt,h,py};do :;done

shopt -s nocaseglob also works with bash 3.2.