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

Re: Can I do without "eval" here?



    Hi Ronald :)

 * Com MN PG P E B Consultant 3 <mn-pg-p-e-b-consultant-3.com@xxxxxxxxxxx> dixit:
> What I don't like in this example, is the usage of eval. Although
> it is harmless in this particular case, the filename 'foo', which
> is hardcoded here, comes in as a parameter too in my real
> application, and this means that it undergoes one level of
> evaluation too, which would yield wrong results when it contains,
> say, a $ character.

    Try this:

    eval whatevercommand \''$file'\'

    As for doing the same without eval, it can be done, too, by
setting the sh_word_split option and tweaking, or simply with this:

    options=("-x")
    (($#)) && options=("-y" "$1")
    CMD $options[1] $options[2] foo

    If "foo" comes from a parameter, just use that parameter instead
of "foo".

    I haven't tested the solution, so it may need some refinement,
but it should do.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to... RAmen!



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