zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Tip of the day / stupid glob qualifier tricks
Date: Wed, 19 Aug 2015 22:22:43 -0700	[thread overview]
Message-ID: <150819222243.ZM28203@torch.brasslantern.com> (raw)

When-you-see-it department.

Consider this proposed solution:

% print *(e*'reply=( this ${REPLY}* )'*)

What problem is this solving?

To use the (e) glob qualifier, you need two things:
(1) a quoted shell command to be eval'd, which includes either a test,
    an assignment to the reply array, or both
(2) a pair of delimiters that do not appear anywhere in the quoted
    shell command

So the problem is to find a pair of delimiters that always satisfy the
second requirement, no matter what appears in the shell command.

On first look you'd expect the proposed solution above to fail the second
requirement, because "*" appears three times.  And yet it works.  Why?


When * appears outside the quotes, it gets tokenized.  Therefore it can
only match another tokenized * and the next one that qualifies is at the
far end of the quoted command.  This also works with ? and ^ if you find
one of those more readable.  I only discovered this effect tonight, but
I believe I might prefer ? because it is not otherwise a glob qualifier.

Can any of you find a valid command string that breaks this trick?


                 reply	other threads:[~2015-08-20  5:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=150819222243.ZM28203@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@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).