0
shopt -s nocaseglob
        ext=.csv
        if [[ $i != "IMCO_"*$ext ]]; then

thecondition is only recognizing when $i (which is a filename) ends with the extension (.csv) in lowercase.

I need it to recognize .CSV uppercase as well

2 Answers2

1

nocaseglob only applies to filename expansion.

Your code works fine if you enable nocasematch instead.

This prints Match:

i="IMCO_FOO.CSV"
shopt -s nocasematch
ext=.csv
if [[ $i != "IMCO_"*$ext ]]; then
  echo "No match"
else
  echo "Match"
fi
that other guy
  • 116,971
  • 11
  • 170
  • 194
0

Using :

ext=csv

shopt -s nocasematch
if [[ $i =~ ^IMCO_.*\.${ext}$ ]]; then

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108