Globbing and hidden files in zsh

If none of the more specific forums is the right place to ask

Globbing and hidden files in zsh

Postby dbbolton » 2011-03-10 04:52

This really doesn't make sense to me:
Code: Select all
% ls -a ~/bin | grep '\.swp'
.pc.swp
.perlbrew.swp
.zed.swp


% ls -a ~/bin/*.swp
ls: cannot access /home/daniel/bin/*.swp: No such file or directory


% ls -a ~/bin/.*.swp
/home/daniel/bin/.pc.swp  /home/daniel/bin/.perlbrew.swp  /home/daniel/bin/.zed.swp
GitHub | zsh docs in Letter PDF

Telemachus wrote:Put down the CGI.
User avatar
dbbolton
 
Posts: 2133
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Globbing and hidden files in zsh

Postby nadir » 2011-03-10 05:25

dbbolton wrote:This really doesn't make sense to me:
Code: Select all
% ls -a ~/bin | grep '\.swp'
.pc.swp
.perlbrew.swp
.zed.swp


% ls -a ~/bin/*.swp
ls: cannot access /home/daniel/bin/*.swp: No such file or directory


% ls -a ~/bin/.*.swp
/home/daniel/bin/.pc.swp  /home/daniel/bin/.perlbrew.swp  /home/daniel/bin/.zed.swp

It is not related to zsh:
Code: Select all
luzer$ echo $SHELL
/bin/bash
luzer$ ls -a ~/* | grep .rc
luzer$

* seems to chomp the hidden files of -a
"seems" means: obviously.

while here:
Code: Select all
% ls -a ~/bin/.*.swp

the second dot is superfluos. the * will match the dot at that end.
people often use the .end to indicate its the end, but it usually is not necessary.
or do english words exist which contain the string swp at the end?

clear? gibberish?
i am not sure myself.
Just do:
%bash
and you will see.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

Re: Globbing and hidden files in zsh

Postby dbbolton » 2011-03-10 05:36

nadir wrote:It is not related to zsh:
Code: Select all
luzer$ echo $SHELL
/bin/bash
luzer$ ls -a ~/* | grep .rc
luzer$


Are you assuming that zsh and bash have the exact same code for globbing?

Your example isn't helpful because I can't see any files in that directory that in fact end in 'rc' (grep should treat a dot as any single character except \n).

* seems to chomp the hidden files of -a
"seems" means: obviously.

Why is that obvious? Does your shell also have an 'extended_glob' option that is in use?

Also, I'm not sure what you mean by 'chomp'. In perl it means 'remove trailing \n'.

while here:
Code: Select all
% ls -a ~/bin/.*.swp

the second dot is superfluos. the * will match the dot at that end.

Actually it's not superfluous because in the task at hand I didn't want to match something like '.abcswp'. Anyway, the point was simply to show that adding the initial dot changes the result (unexpected behavior).

EDIT: After some searching, I found the option I wanted on the zsh wiki (so yes, it was related to my shell): http://zshwiki.org/home/options/expn
GitHub | zsh docs in Letter PDF

Telemachus wrote:Put down the CGI.
User avatar
dbbolton
 
Posts: 2133
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Globbing and hidden files in zsh

Postby nadir » 2011-03-10 05:58

Code: Select all
luzer$ echo $SHELL
/bin/bash
luzer$  ls -a ~/Data/bin | grep '\.swp'
.pc.swp
.perlbrew.swp
.zed.swp
luzer$  ls -a ~/Data/bin/*.swp
ls: cannot access /home/m1arkust/Data/bin/*.swp: No such file or directory
luzer$ ls -a ~/Data/bin/.*.swp
/home/m1arkust/Data/bin/.pc.swp        /home/m1arkust/Data/bin/.zed.swp
/home/m1arkust/Data/bin/.perlbrew.swp
luzer$


I assume nothing. I use chomp like in chomp. I only say that in this very case you get exactly the same result in Bash.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

Re: Globbing and hidden files in zsh

Postby dbbolton » 2011-03-10 07:53

nadir wrote:I assume nothing.

You assumed (or at least conjectured, but I don't know why someone would propose a solution that he believed to be false) that it wasn't related to the shell because a different shell gave the same result, which turned out to be wrong.
I use chomp like in chomp.

Bit of a tautology. It seems to suggest that there's only one possible meaning for the term, and any ambiguity is totally out of the question. The only other meaning I know for this word is 'bite' or 'chew'. Neither really makes sense, since I think you meant that the shell was either ignoring the dot files or removing them from the glob's array (or that they were never added to the array).
I only say that in this very case you get exactly the same result in Bash.

And that's true, until you setopt glob_dots in zsh:

Code: Select all
% ls dots
a.ext  b.ext  dext


%ls -a dots
.  ..  a.ext  b.ext  dext  .eext  .f.ext  .g.ext


% ls dots/*
dots/a.ext  dots/b.ext  dots/dext  dots/.eext  dots/.f.ext  dots/.g.ext


% ls dots/.*.ext
dots/.f.ext  dots/.g.ext


% ls dots/.*ext
dots/.eext  dots/.f.ext  dots/.g.ext
GitHub | zsh docs in Letter PDF

Telemachus wrote:Put down the CGI.
User avatar
dbbolton
 
Posts: 2133
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Globbing and hidden files in zsh

Postby llivv » 2011-03-10 09:17

dbbolton wrote:[...]
And that's true, until you setopt glob_dots in zsh:
Code: Select all
% ls dots
a.ext  b.ext  dext
%ls -a dots
.  ..  a.ext  b.ext  dext  .eext  .f.ext  .g.ext
% ls dots/*
dots/a.ext  dots/b.ext  dots/dext  dots/.eext  dots/.f.ext  dots/.g.ext
% ls dots/.*.ext
dots/.f.ext  dots/.g.ext
% ls dots/.*ext
dots/.eext  dots/.f.ext  dots/.g.ext

Oh. I think?
I hate when that happens...
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.
User avatar
llivv
 
Posts: 5488
Joined: 2007-02-14 18:10
Location: cold storage

Re: Globbing and hidden files in zsh

Postby nadir » 2011-03-10 16:29

dbbolton wrote:
nadir wrote:I assume nothing.

You assumed (or at least conjectured, but I don't know why someone would propose a solution that he believed to be false) that it wasn't related to the shell because a different shell gave the same result, which turned out to be wrong.
I use chomp like in chomp.

Bit of a tautology. It seems to suggest that there's only one possible meaning for the term, and any ambiguity is totally out of the question. The only other meaning I know for this word is 'bite' or 'chew'. Neither really makes sense, since I think you meant that the shell was either ignoring the dot files or removing them from the glob's array (or that they were never added to the array).
I only say that in this very case you get exactly the same result in Bash.

And that's true, until you setopt glob_dots in zsh:

Code: Select all
% ls dots
a.ext  b.ext  dext


%ls -a dots
.  ..  a.ext  b.ext  dext  .eext  .f.ext  .g.ext


% ls dots/*
dots/a.ext  dots/b.ext  dots/dext  dots/.eext  dots/.f.ext  dots/.g.ext


% ls dots/.*.ext
dots/.f.ext  dots/.g.ext


% ls dots/.*ext
dots/.eext  dots/.f.ext  dots/.g.ext


a) it is not wrong, but right:
both shells give the same behavior for the example you gave.

b) at least my dictionary gives me only one meaning for chomp (my both dictionaries ding and artha).
to chew on something -> after that it is away. See? Easy.
(the german words makes it more easy: zermalmen).
I could or should have used swallow.

c) you did not say you want to change it. You said:
This really doesn't make sense to me:

I said why it makes sense: cause the * swallows the hidden files, which the -a hits.

d)
And that's true, until you setopt glob_dots in zsh:

yup 2+2 is not 4, because _after_ i a add a +1 it is wrong.

PS: you really got fileendings like: .abcswp? That is the result for my complete filesystem (ca 200GB of data)
I will stress this: it is not a single dir ->
$ locate swp
/home/m1arkust/.perl5/perlbrew/build/perl-5.12.3/cpan/Module-Pluggable/t/lib/EditorJunk/Plugin/Bar.pm.swp
/home/m1arkust/Build/Kernel/Linux/linux-source-2.6.38-rc6/Documentation/arm/swp_emulation
/home/m1arkust/Build/Kernel/Linux/linux-source-2.6.38-rc6/arch/arm/kernel/swp_emulate.c
/home/m1arkust/Programming/Bash/Training/TEST/tmp/.swp
/home/m1arkust/Programming/Bash/Training/special/opts/getopts/.first_test.sh.swp
/home/m1arkust/Programming/Bash/Training/special/opts/getopts/.new_shorty.sh.swp
/home/m1arkust/Programming/Bash/Training/text_editing/IO-redirection/.test.txt.swp
/home/m1arkust/Programming/Bash/Training/text_editing/IO-redirection/.test_emul.txt.swp
/home/m1arkust/Programming/HTML/my_web_page/backup/start-web-page/content/computing.content/bookmarks.content/.news.html.swp
/home/m1arkust/Programming/HTML/my_web_page/start-web-page/content/computing.content/bookmarks.content/.news.html.swp
/home/m1arkust/Programming/Perl/Training/variables/hashes/.example_soul.pl.swp
/home/m1arkust/SharedFolder/configs/themes/gtk-themes/B_and_W-gtk/gtk-2.0/.gtkrc.swp
/root/Temp/.grub.swp
/usr/lib/linuxmint/mint-debian-installer/.mint-debian-installer.py.swp
/usr/share/doc/linux-doc-2.6.36/html/rapidio/API-rio-get-swpinfo-inport.html
/usr/share/doc/linux-doc-2.6.36/html/rapidio/API-rio-get-swpinfo-tports.html
/usr/share/themes/B_and_W-gtk/gtk-2.0/.gtkrc.swp
/var/tmp/.swp
/var/tmp/cpuinfo.swp
$
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

Re: Globbing and hidden files in zsh

Postby dbbolton » 2011-03-10 18:51

a) it is not wrong, but right:

That depends on what you're referring to.
"in this very case you get exactly the same result in Bash." == 1
"It is not related to zsh:" == 0

I said why it makes sense: cause the * swallows the hidden files, which the -a hits.

That really isn't an explanation but a repetition of what I already new when I wrote the first post. I was interested in why the shell would not glob dot files. Sure, I could have been more specific and said "I want the shell to glob dot files too".

PS: you really got fileendings like: .abcswp?

Probably not, but when dealing with any kind of regular expression, my default approach is to include as much information as I already know in order to be as specific as possible. It never hurts to be too specific, especially when you are moving or unlinking files.
GitHub | zsh docs in Letter PDF

Telemachus wrote:Put down the CGI.
User avatar
dbbolton
 
Posts: 2133
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Globbing and hidden files in zsh

Postby nadir » 2011-03-10 19:33

dbbolton wrote:
I said why it makes sense: cause the * swallows the hidden files, which the -a hits.

That really isn't an explanation but a repetition of what I already new when I wrote the first post. I was interested in why the shell would not glob dot files. Sure, I could have been more specific and said "I want the shell to glob dot files too".

That is exactly the reason why i said:
nadir wrote:* seems to chomp the hidden files of -a
"seems" means: obviously.

You then asked: Why is that obvious?
Now you say: but it is obvious.

The why is probably that the wildchard * doesn't match hidden files and has a higher "importance" than the option of the command (kinda overwrites it, -a says use hidden files, but * says don't use them).
For me it is enough to know that it is that way, hence i will not hunt for the exact explanation.

This way, that way:
zsh is an amazing shell.
I hope you are a bit less unhappy in case i admit that
(otoh there is shopt -s dotglob )

PS: let me search for the correct term for what i call importance.
Got it: precedence.

In case that is what you wanted:
You did _not_ ask: "how can i make * to match hidden files too?" I had no idea you wanted that.
Was that the question?
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

Re: Globbing and hidden files in zsh

Postby dbbolton » 2011-03-10 21:39

nadir wrote:You then asked: Why is that obvious?
Now you say: but it is obvious.

The what is obvious, but the why not.

The why is probably that the wildchard * doesn't match hidden files and has a higher "importance" than the option of the command (kinda overwrites it, -a says use hidden files, but * says don't use them).
For me it is enough to know that it is that way, hence i will not hunt for the exact explanation.

My understanding (which might be and probably is wrong) is that the glob creates an array which the shell passes to the given command. If the shell's glob function ignores dot files, then it makes sense why they won't show up even with 'ls -a'. But I'm still not sure why this is the default behavior. Did the bash/zsh developers decide that globbing hidden files is 'dangerous' or just 'annoying'?
GitHub | zsh docs in Letter PDF

Telemachus wrote:Put down the CGI.
User avatar
dbbolton
 
Posts: 2133
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Globbing and hidden files in zsh

Postby L_V » 2019-10-21 17:15

For zsh 5.7 (buster), extended globbing can be used and declared in ~/.zshrc

Code: Select all
setopt extendedglob

zsh can directly and recursively find any hidden files or directory with (D) suffix, according to zsh_refcard.pdf (page 3).
**/ : Directories to any level
D : Leading dots may be matched

example: find with ls any .conf file in home directory
Code: Select all
cd ~
ls **/*.conf
zsh: no matches found: **/*.conf
# -----------------------
ls **/*.conf(D)
.config/fontconfig/fonts.conf 
.config/vlc/vlc-qt-interface.conf
.../...

To anticipate next comment which will remind that this post has been open in 2011, answer is that zsh is a powerful shell which has been adopted in June 2019 by MacOS as default shell, as replacement of bash .
L_V
 
Posts: 1126
Joined: 2007-03-19 09:04


Return to General Questions

Who is online

Users browsing this forum: No registered users and 20 guests

fashionable