I'm trying the following globs in a bash shell:

$ ls -d .*
.  ..  .a  .ab
$ ls .a*
.a  .ab
$ ls .[!.]*
.a  .ab
$ ls .[!.]?*

Shouldn't the last expression mean "a dot followed by exactly one non-dot followed by zero or more characters"? Why does it fail to match .a?


You are mistaken. It means "a dot followed by exactly one non-dot followed by one character followed by zero or more characters". .a does not have enough characters to match it.

But really, just set dotglob.

| improve this answer | |
  • Thanks, I thought the question mark referred to the non-dot. No need to set dotglob, just playing around. :) – 3lectrologos Apr 9 '12 at 16:43
  • 1
    If you were using regular expressions, then "[^.]?" would mean either a single non-dot character, or no characters. But in shell globbing syntax "?" matches any single character (basically, "?" in shell globbing is equivalent to "." in regular expressions). – MadScientist Apr 9 '12 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.