Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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