zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Greg Klanderman <gak@klanderman.net>, Zsh list <zsh-workers@zsh.org>
Subject: Re: pattern matching, when the pattern is a parameter expansion
Date: Wed, 3 Feb 2021 16:03:52 +0000 (GMT)	[thread overview]
Message-ID: <159533057.3538925.1612368232803@mail2.virginmedia.com> (raw)
In-Reply-To: <24602.50825.244206.559048@lwm.klanderman.net>

> 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.
(I find this somewhat inconvenient as it makes subscript arguments
hard to quote.)

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.

% x='t*'
% [[ two == $~x ]] && echo yes || echo no
yes

pws


  reply	other threads:[~2021-02-03 16:04 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 [this message]
2021-02-03 18:30   ` Greg Klanderman

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=159533057.3538925.1612368232803@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=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).