Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are mixed-case filenames returned when using bash set construct wildcard?

Tags:

bash

I set up a few files to understand bash's set construct wildcard, i.e. [].

ls *
1  2  A  bob  darlene  dave  ed  frank  fred  LS_example.sh  Z

The files I expected to be returned by ls [a-z]* would only include the ones beginning with a lower-case letter, but in the following, files beginning with an upper-case letter are also returned:

ls [a-z]*
A  bob  darlene  dave  ed  frank  fred  LS_example.sh

Can you explain this behavior?

like image 761
user1443561 Avatar asked Feb 11 '26 00:02

user1443561


1 Answers

In your locale (and the way it's defined in your OS), [a-z] includes the upper and lower case letters. If you want to reliably match lowercase letters, do this:

ls [[:lower:]]*
like image 144
Dennis Williamson Avatar answered Feb 12 '26 16:02

Dennis Williamson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!