Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Tip of the day / stupid glob qualifier tricks



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?



Messages sorted by: Reverse Date, Date, Thread, Author