Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Tip of the day / stupid glob qualifier tricks
- X-seq: zsh-users 20439
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Tip of the day / stupid glob qualifier tricks
- Date: Wed, 19 Aug 2015 22:22:43 -0700
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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