Re: more file filtering (e::), stest, perl (Re: A question about filename generate)

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAHYJk3TPbzc3viJLaQ4tqNpdEFiVDEe7hw=01xpjXocmiEjkiQ@mail.gmail.com>
On Mon, Jul 28, 2025 at 6:53 PM Bart Schaefer <[email protected]> wrote:
>
> On Mon, Jul 28, 2025 at 8:17 AM Marc Chantreux <[email protected]> wrote:
> >
> > if you read the 'FILENAME GENERATION' section from zshexpn, you'll see
> > that ^x exists, x~y exists but there is no thing such x^y.
>
> Not precisely true, as PWS mentioned.  This could perhaps be clarified
> in the manual.  You can append ^y to a pattern but x^y doesn't imply
> negation of the entirety of x, rather it means "x followed by anything
> not y".  The precedence is also a little confusing; e.g., * has higher
> precedence than ^ so
>
> % print configure*
> configure configure.ac configure.ac.orig
> % print configure*^.orig
> configure configure.ac configure.ac.orig
> % print configure^*.orig
> configure configure.ac
>
> That is, in x^y the x pattern is fully expanded and then must not be
> followed by the y pattern.

The best explanation I've come up with for ^y is this:
  ^foo is like a * that cannot expand to a string matching the pattern foo.

There's no need for x to be given, just ^foo is a valid pattern. x^y
isn't a specific pattern any more than x* is. x^y isn't logically any
different from (^y)x other than needing parentheses in the latter
case. (I'm sure you know all this, but I just wanted to clarify these
points.)

Perhaps there was a misunderstanding when Marc said "there is no such
thing x^y" where he was referring to entries in the manpage. It is of
course valid to write x^y because you can combine any of the globbing
elements however you like.

As a sidenote, ^x^y is also valid, although it is not very useful (one
"star" will always expand to the entire filename while the other
expands to the empty string, except for the case where x == y while
they are also just a single character. In the case of ^foo^foo, one
can expand to fo while the other expands to o, and the whole pattern
successfully matches foo, for example.)

-- 
Mikael Magnusson
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.