Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: protect spaces and/or globs
On 2021-02-11 9:19 a.m., Lawrence Velázquez wrote:
Why are you still accreting grepargs like this? Peter has already
shown you how to do this.
grepargs=("$@")
Unless your actual code actually modifies the args before adding
them to the array?
Not modified but the ordering is different so I hafta grab them one at a
time.
Good point tho, all else equal I see that Peter's method is better.
[...]
% pat='on the current' foo='i,2,light edit' bar='i,1,old stable'
% grep_wrapper $pat $foo $bar
what should be going to history:
grep --color=always -i -- 'on the current' 'i,2,light edit' 'i,1,old stable'
Yes, point made. I know that if I want something expanded I don't
single quote it. But indeed
I shouldn't say 'exactly as typed' because I know that variables will be
expanded.
[...]
A ${(q-)foo} expansion basically re-quotes the value of foo so
it works correctly with eval, in whatever way is requested. It
doesn't know the value's origins.
That's a subtle but important point. I could think of it as
'protection' but then
how did the variable expand? As you say it must be seen as re-quoting.
Thanks
for catching it.
That's not how quoting works. Quote levels don't nest to produce
some kind of super-quoting. You're misinterpreting the results of
your experimentation.
% foo='a b c'
% print -r 'protected: $foo'
protected: $foo
% print -r "'not protected: $foo'"
'not protected: a b c'
The double quotes do protect the single quotes from being interpreted
by the shell, but they also permit expansions.
That is a critical point. You know, it is so easy to think you've 'got
it' when you don't.
I'm going to take the above and write it to a sticky note a stick it to
my desk. Very
insightful of you to realize that I'm not seeing things right, many thanks.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author