Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: A question about filename generate



> On 28/07/2025 15:25 BST Perry Smith <pedz@xxxxxxxxxxxxxxxx> wrote:
> I looked at my zsh cheat sheet and saw two other patterns that I
> thought I would ask about if anyone would be so kind:
>
> I’m assuming that pat of the expression ^pat is a glob pattern.  And
> x^y: my guess is that both x and y are glob patterns.

y is a glob pattern, but there are a couple of things you need to be
careful about.

When the manual entry says "this has a higher precedence than /" it
effectively means that something like ^foo/bar is equivalent to
(^foo)/bar, in other words search any directory other than foo for a
file bar.  Explicitly:

% print -l **/*.txt
dir1/a.txt
dir2/b.txt
% print -l ^*1/*.txt
dir2/b.txt

The other point is that when you have x^y it means first match x, then
match anything that's not y.  It's not an exclusion this time.

Explicitly:

% print -l *
foobar
foopub
% print -l foo^bar
foopub

First match foo, *then* match anything that isn't "bar".

cheers
pws




Messages sorted by: Reverse Date, Date, Thread, Author