zsh-workers
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-workers@zsh.org
Subject: Re: pattern matching, when the pattern is a parameter expansion
Date: Wed, 03 Feb 2021 13:30:01 -0500	[thread overview]
Message-ID: <87eehx3sye.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <159533057.3538925.1612368232803@mail2.virginmedia.com> (Peter Stephenson's message of "Wed, 3 Feb 2021 16:03:52 +0000 (GMT)")

>>>>> On February 3, 2021 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:

>> On 03 February 2021 at 15:51 Greg Klanderman <gak@klanderman.net> wrote:
>> % x='t*'
>> % [[ two == $x ]] && echo yes || echo no
>> no
>> % echo "${(@)z:#$x}"
>> one two three
>> % echo "${z[(i)$x]}"
>> 2
>> 
>> I would have actually expected to match in the first two cases as
>> well; is this behavior of using plain string matching when the pattern
>> is a parameter expected documented?

> To cut a long story short: the third case is actually the odd one out.
> Subscripts always treat the argument as a pattern --- the basic doc
> for that is the under the "r" subscript flag, to which "i" refers.

Ahh now I see it.. I had read the doc under 'r' and 'i', but the note
which describes this is under 'R', and I didn't continue reading that
one after the first sentence "Like 'r'  but gives the last match".  I
should know after ~25 years to read everything anywhere nearby for all
the additional nuggets...

> (I find this somewhat inconvenient as it makes subscript arguments
> hard to quote.)

But you can just use the 'e' flag, right?

> Otherwise, substituted pattern characters are not active by default:
> see the GLOB_SUBST option.  You can turn this on with a "~" after
> the "$", see the description of ${~spec} in the zshexpn manual.

Thanks for pointing that out.. another hidden nugget!

I wouldn't have guessed the globbing option would turn that on,
but of course it makes sense once you know..

I just found 'jobs -Z' yesterday; never in a million years would I
have guessed that functionality would be associated with 'jobs' but
found it reading the source code to determine how hard it would be
to add just such a feature!

Greg


      reply	other threads:[~2021-02-03 18:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 15:51 Greg Klanderman
2021-02-03 16:03 ` Peter Stephenson
2021-02-03 18:30   ` Greg Klanderman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eehx3sye.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).