I often find it annoying (or worse) when I type

command .*

in bash and the command applies to the parent directory and current directory. Is there some shell option or other configuration I can tweak to make bash exclude . and .. from the expansion of .*?

link|improve this question

56% accept rate
feedback

1 Answer

up vote 4 down vote accepted

In bash, in this order:

GLOBIGNORE=.
shopt -u dotglob

When GLOBIGNORE is set, . and .. are automatically ignored, so you dont actually need to set them in GLOBIGNORE, but if you have nothing else to ignore you wont have anything to set it to.

Every time you set GLOBIGNORE to a non-null value, bash turns on the option dotglob, so you will need to turn it off afterwards; otherwise bash will expand * to include files starting with a dot.

link|improve this answer
Cool, thanks! I actually would rather have dotglob turned on, so setting GLOBIGNORE sounds perfect. – David Zaslavsky Aug 21 '10 at 22:04
feedback

Your Answer

 
or
required, but never shown

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