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.

Thereotically, the result of command echo * should be "Any file in the current directory". Should it include the dotfile?

Similarly, Should the result of ls * include the dotfile?

share|improve this question
    
What is list? Do you mean ls? –  terdon Jul 20 '13 at 14:02
    
Yes, I am sorry for the misspelling. I have updated it. –  user43312 Jul 20 '13 at 21:37

1 Answer 1

up vote 5 down vote accepted

From the Filename Expansion section of the GNU bash reference:

When a pattern is used for filename expansion, the character ‘.’ at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option dotglob is set. When matching a file name, the slash character must always be matched explicitly. In other cases, the ‘.’ character is not treated specially.

This is documented (and expected) behaviour in all POSIX shells, see Patterns Used for Filename Expansion:

If a filename begins with a period ( '.' ), the period shall be explicitly matched by using a period as the first character of the pattern or immediately following a slash character. The leading period shall not be matched by:

  • The asterisk or question-mark special characters

  • A bracket expression containing a non-matching list, such as "[!a]", a range expression, such as "[%-0]", or a character class expression, such as "[[:punct:]]"

It is unspecified whether an explicit period in a bracket expression matching list, such as "[.abc]", can match a leading period in a filename.

share|improve this answer
    
In bash (which is the default shell for most linux distros) you can set the mentioned dotglob option with shopt -s dotglob, and then * will match files starting with a dot as well as those that don't. Unset it with shopt -u dotglob. –  evilsoup Jul 20 '13 at 19:34
    
You should mention that the * is being expanded by bash (or whatever your shell is) and then passed on to the echo or ls commands, and not the commands themselves. –  jsbillings Jul 20 '13 at 23:30
    
@jsbillings Considering the documentation I linked to is that of the bash/POSIX shell manuals, I don't think that's necessary to mention. –  Chris Down Jul 21 '13 at 9:31
    
Thank you. That is what I wondering. –  user43312 Jul 23 '13 at 22:53

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.