I\'ve noticed for a while now that, on some of the Unix-based systems I use at least, ls [A-Z]*
has been giving me the results I would anticipate from ls [A-Z
It's actually [A-Za-y]
, and it has to do with language collation. If you want to override it then set $LC_COLLATE
appropriately; either of C
or POSIX
should do.
Unix shells don't actually use regular expressions, but glob patterns, which are distinctly different from regexes. One difference is that they are implicitly anchored to the start and end of the string - e.g. ls foo[a-z]
will list the file food
, but not fooble
. It's not actually ls
doing the matching here, but the shell itself. Globs are also usually sometimes case insensitive (depending on the implementation).
Take a look at the manpage for your favourite interactive shell and read about glob matching - for example bash's manpage about filename expansion describes the syntax it uses.
It depends on your locale. If you want that [A..Z]
only matches capital letters, you could use C locale: set LC_COLLATE
or LC_ALL
to C
.
LC_ALL=C
ls [A..Z]*
bash manual, pattern matching