Given the following:
$ echo $BASH_VERSION
4.2.10(1)-release
$ shopt | fgrep case
nocaseglob off
nocasematch off
$ case A in [a-z]) echo TRUE;; esac
TRUE
I expect that the capital letter A should not match the lower-case character class of [a-z], but it does. Why doesn’t this match fail?
You can’t reliably use the dash this way. If I don’t use dashes, it works as expected:
But with dashes, it prints TRUE regardless of the setting of
nocasematch.Bash is doing pattern matching here. Check out this section of the reference manual where it says that using the hyphen MIGHT interpret
[a-z]as[A-Za-z]! It tells you how to get the traditional interpretation (set LC_COLLATE or LC_ALL to C). Basically your default locale is sorting in dictionary order. The reference manual explains things pretty well.ADDENDUM
Okay I have a transcript for you.