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.

After coming from cygwin, I'm quite confused about the bash (version 4.1.5) globbing on my Ubuntu 10.4. I'd love one of the following two possibilities:

  • ignore . and .., match everything else
  • ignore filenames starting with a dot unless given explicitly

The current behavior is plain strange:

cd; ls .*

says "ls: cannot access .*: No such file or directory" although I explicitly asked for filenames starting with a dot.

cd; ls .gnupg/*.gpg

complains as well although I'm asking for files not starting with a dot (it's just the directory name what starts with a dot).

Output of shopt -p

(removed)

The solution

I've changed shopt to values from another user (not having this problem) and it didn't help. Then I came to the idea to bisect my .bashrc and find the offending line which contained something like GLOBIGNORE='.[!/.]*:..[!/]*:*/.[!/.]*:*/..[!/]*:...

I've replaced it by GLOBIGNORE='.:..', which does nearly what I want, and it works.

share|improve this question
    
I've never seen this behavior. Could you edit your question to include the output of shopt -p, please? –  Arcege Mar 12 '12 at 21:29
    
This behavior is very strange, indeed. I edited my question. –  maaartinus Mar 12 '12 at 23:04

3 Answers 3

The "ls: cannot access .*: No such file or directory" error sounds like there are permissions problems with the current directory. I can reproduce it with:

$ mkdir -p ~/tmp/tmp
$ cd ~/tmp/tmp
$ ls .*
.:

..:
tmp
$ chmod u-r .
$ ls .*
ls: cannot access .*: No such file or directory
$ ls -ldn .
d-wxr-xr-x 2 1000 1000 4096 2012-03-12 18:31 .
$ chmod u+r .
$ ls .*
.:

..:
tmp

I'd suggest running chmod +r . and trying the ls .* again.

share|improve this answer
    
That's interesting, but can't be the cause. The concerned directory is my $HOME and the permissions are right (700). –  maaartinus Mar 13 '12 at 2:29
up vote 1 down vote accepted

Unfortunately, I must answer my own question. It was GLOBIGNORE. From the man page:

A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of matches.

share|improve this answer

It is more than likely that you have no files being matched by the globs. If no files are matched, bash by default interprets * literally. You may wish to set nullglob using shopt -s nullglob to avoid this (although this will leave the command barren of arguments altogether if no files are matched).

share|improve this answer
    
You're right in what you're saying about not matching. But it should match, there're tons of .foo files in my home directory, etc. –  maaartinus Mar 12 '12 at 22:09
1  
At the very least, .* should match . and .., which means it should always match. –  Matthew Scharley Mar 13 '12 at 0:34
    
@MatthewScharley - Ah, good point. –  Chris Down Mar 13 '12 at 3:12

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.