zsh-users
 help / color / mirror / code / Atom feed
* Tip of the day / stupid glob qualifier tricks
@ 2015-08-20  5:22 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2015-08-20  5:22 UTC (permalink / raw)
  To: zsh-users

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?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-20  5:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-20  5:22 Tip of the day / stupid glob qualifier tricks Bart Schaefer

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).