Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: protect spaces and/or globs
On Wed, Feb 10, 2021 at 8:19 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2021-02-10 7:47 a.m., Peter Stephenson wrote:
> >
> > No eval needed, the arguments are now exactly the correct command arguments.
> >
> If you look at this one case indeed no eval is needed, but in the
> broader context of the way all
> my functions work, the eval is unavoidable. Or is it? Maybe not.
Even if you do need "eval", you should still use an array. That is, instead of
sstring="grep --color=always -i -- ${grepargs[@]}"
eval "$sstring"
use
sarray=(grep --color=always -i -- "${grepargs[@]}")
eval "${(@q)sarray}"
Using (@q) causes each individual array element to be quoted
separately. The double quotes then expand it in the manner of
"${sarray[@]}".
Messages sorted by:
Reverse Date,
Date,
Thread,
Author