* question about glob qualifier format (#qx)
@ 2013-09-20 11:11 Han Pingtian
2013-09-20 11:38 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Han Pingtian @ 2013-09-20 11:11 UTC (permalink / raw)
To: zsh-users
Hello,
I'm confused about the usage of glob qualifier format "(#qx)". The man
page says:
...... Also, as the syntax is unambiguous,
the expression will be treated as glob qualifiers just as long any
parentheses contained within it are balanced; appearance of `|', `(' or
`~' does not negate the effect.
But looks like if I put them in parentheses, it will not take effect any more:
$ ls
1.c 2.h a b slink
$ echo *((#q/))
1.c 2.h a b slink
So I'd like to know how to comprehend the manpage here? Thanks in
advance!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about glob qualifier format (#qx)
2013-09-20 11:11 question about glob qualifier format (#qx) Han Pingtian
@ 2013-09-20 11:38 ` Peter Stephenson
2013-09-20 23:39 ` Han Pingtian
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2013-09-20 11:38 UTC (permalink / raw)
To: zsh-users
On Fri, 20 Sep 2013 19:11:10 +0800
Han Pingtian <hanpt@linux.vnet.ibm.com> wrote:
> I'm confused about the usage of glob qualifier format "(#qx)". The man
> page says:
>
> ...... Also, as the syntax is unambiguous,
> the expression will be treated as glob qualifiers just as long any
> parentheses contained within it are balanced; appearance of `|', `(' or
> `~' does not negate the effect.
>
> But looks like if I put them in parentheses, it will not take effect any more:
>
>
> $ ls
> 1.c 2.h a b slink
> $ echo *((#q/))
> 1.c 2.h a b slink
>
> So I'd like to know how to comprehend the manpage here? Thanks in
> advance!
Because of the ambiguity between glob qualifiers without the #q and
parenthesised groups, the shell guesses which is which. An expression
containing "|" makes it guess that it's a parenthesised group rather
than a set of glob qualifiers. However, if the *first* open parenthesis
(there's no reason to double them) is followed by #q (and EXTENDED_GLOB
is set), it knows for sure that this is a glob qualifier, so it doesn't
need to do any guessing.
This is there as an additional help; you don't need to change your
normal use of glob qualifiers just because you've signalled them
explicitly with #q. (#q/) works fine.
pws
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about glob qualifier format (#qx)
2013-09-20 11:38 ` Peter Stephenson
@ 2013-09-20 23:39 ` Han Pingtian
2013-09-21 8:30 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Han Pingtian @ 2013-09-20 23:39 UTC (permalink / raw)
To: zsh-users
On Fri, Sep 20, 2013 at 12:38:30PM +0100, Peter Stephenson wrote:
> On Fri, 20 Sep 2013 19:11:10 +0800
> Han Pingtian <hanpt@linux.vnet.ibm.com> wrote:
> > I'm confused about the usage of glob qualifier format "(#qx)". The man
> > page says:
> >
> > ...... Also, as the syntax is unambiguous,
> > the expression will be treated as glob qualifiers just as long any
> > parentheses contained within it are balanced; appearance of `|', `(' or
> > `~' does not negate the effect.
> >
> > But looks like if I put them in parentheses, it will not take effect any more:
> >
> >
> > $ ls
> > 1.c 2.h a b slink
> > $ echo *((#q/))
> > 1.c 2.h a b slink
> >
> > So I'd like to know how to comprehend the manpage here? Thanks in
> > advance!
>
> Because of the ambiguity between glob qualifiers without the #q and
> parenthesised groups, the shell guesses which is which. An expression
> containing "|" makes it guess that it's a parenthesised group rather
> than a set of glob qualifiers. However, if the *first* open parenthesis
> (there's no reason to double them) is followed by #q (and EXTENDED_GLOB
> is set), it knows for sure that this is a glob qualifier, so it doesn't
> need to do any guessing.
>
> This is there as an additional help; you don't need to change your
> normal use of glob qualifiers just because you've signalled them
> explicitly with #q. (#q/) works fine.
>
> pws
But I'm still confusing on the manpage :)
If I want to list all symbolic links and directories in current
directory, this expression doesn't work:
$ echo (*(#q@)|*(#q/))
we must write it as :
$ echo *(#q@) *(#q/)
I cannot see any difference between '(#qx)' format and 'bare glob
qualifier' format on being disabled by '|', '('. Please advise. Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about glob qualifier format (#qx)
2013-09-20 23:39 ` Han Pingtian
@ 2013-09-21 8:30 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-09-21 8:30 UTC (permalink / raw)
To: zsh-users
On Sep 21, 7:39am, Han Pingtian wrote:
}
} But I'm still confusing on the manpage :)
}
} If I want to list all symbolic links and directories in current
} directory, this expression doesn't work:
}
} $ echo (*(#q@)|*(#q/))
A few lines above the excerpt you previously quoted from the manual, it
says:
If the option EXTENDED_GLOB is set, a different syntax for glob
qualifiers is available, namely `(#qx)' where x is any of the same glob
qualifiers used in the other format. The qualifiers must still appear
at the end of the pattern.
} I cannot see any difference between '(#qx)' format and 'bare glob
} qualifier' format on being disabled by '|', '('. Please advise.
The difference is with e.g. (.). With BARE_GLOB_QUAL, *(.) matches all
plain files. With NO_BARE_GLOB_QUAL, *(.) matches files whose name ends
in a dot, and *(#q.) is needed to match all plain files.
} we must write it as :
}
} $ echo *(#q@) *(#q/)
More than one of these lists can be combined, separated by commas. The
whole list matches if at least one of the sublists matches (they are
`or'ed, the qualifiers in the sublists are `and'ed).
So:
% echo *(#q@,/)
*should* do what you want, but see below about potential bugs ....
I accidentally encountered some odd behavior while confirming this.
With NO_EXTENDED_GLOB, #q is not supposed to be available to introduce
qualifiers. However
% setopt NO_EXTENDED_GLOB
% echo *(#q@)
<list of symlinks>
Whereas
% echo *(#q/)
zsh: unknown file attribute
This is inconsistent, that is, sometimes (#q@) will also give "unknown"
and (#q/) will work. The more I play with it the less consistently it
behaves. *(#q@,/) may produce any of
zsh: unknown file attribute
zsh: bad pattern: *(#q@,/)
or the intended list of files, depending on ... well, I can't tell what
it depends on, possibly previous globs or what the current directory is,
or how often EXTENDED_GLOB or BARE_GLOB_QUAL have been toggled on and
off. In fact once I even got:
% setopt CSH_NULL_GLOB
% print -l *(#q@) *(#q/)
zsh: bad pattern: *(#q/)
(even when */ matches several directories, and *(/) matches them with
BARE_GLOB_QUAL). So something about the parsing for #q may be wonky.
All of this works very nicely when BARE_GLOB_QUAL is enabled, which it
is by default, which is probably why nobody noticed before that #q is
doing strange things.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-21 8:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-20 11:11 question about glob qualifier format (#qx) Han Pingtian
2013-09-20 11:38 ` Peter Stephenson
2013-09-20 23:39 ` Han Pingtian
2013-09-21 8:30 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).