Alex Rivera | Logout

What is up with [A-Z] meaning [A-Za-z]?

Asked 2011-01-29T00:43:55.053
12

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-Za-z]*, leaving me unable to easily get a list of just the goddamned files that start with capital letters. I just now ran into the same thing with grep, where I could not get it to stop matching lowercase letters with [A-Z] until I eventually used grep -P to get Perl regex.

So I have some related questions:

  1. When did this idiocy start?
  2. Who is responsible and needs to be punished?
  3. WHY???
  4. Is there some reasonably simple workaround for either or both of the ls and grep cases? (Trying, for example, grep --no-ignore-case was fruitless. grep -P is not a very good workaround because of its experimental feature status.)
Edit
Report

1 Answer

-1

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.

answered 2011-01-29T01:01:57.167

Your Answer