I encountered the following IMHO strange behavior in bash’s file-patterns:
$ ls
Basic1 datei1 datie2 sdfl
$ ls [a-z]*
Basic1 datei1 datie2 sdfl
$ ls [abcdefghijklmnopqrstuvwxyz]*
datei1 datie2 sdfl
Why is the pattern with the range [a-z] not case-sensitive? Bug or feature?
Note:
-
The bash-Option
nocaseglobisoff(otherwise, the second pattern given above should have also been case-insensitive…):$ shopt nocaseglob nocaseglob off -
My bash-version:
$ bash --version GNU bash, Version 4.2.24(1)-release (i686-pc-linux-gnu)
GNU bash, Version 4.2.24(1)-release (i686-pc-linux-gnu)
If you only want file names that start with a lower-case, use
Edit
Answering F. Hauri’s comment: section 3.5.8.1 of the reference manual says it all. But before we read it, let’s play a little bit (YMMV): create a new scratch directory and
So it seems that bash’s alphabetical order (here, on my machine, with my settings) is:
This might explain why you got your results (it seems your settings are similar to mine).
Now, go and read the section 3.5.8.1 of the reference manual and you’ll understand that things are not as simple, that the ordering depends on the value of the environment variable
LC_COLLATE.So try:
Yeah!
Moral
If you want lower cases, don’t use
[a-z]as this will highly depend on the local settings. Instead, use[[:lower:]]. In the reference manual, you’ll also find several other useful character classes.Bottom Line
So, bug or feature? You now have the answer
;-)Hope this helps!