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

Re: array with newlines preserved as literal text



On Tue, Feb 2, 2021 at 11:16 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I create some nasty output involving a grep search, save to to a
> variable, send it to a function which ends up calling 'eval' which
> receives the input and executes it like this:
>
>      @ eval "$@"
>      echo "\nYou (hard return)
>      will\\nregret'\x0a'\nthe day you '\n' were born."

I'm curious why you want to save this in the form of a command to be
eval'd rather than just save the argument string?

Pretty much any time I start to write an "eval" I go back to make sure
I didn't do something wrong earlier. **

Roman's answers are otherwise spot-on.

** Of about 90 instances of "eval" in the contributed Functions
directory, 45 are one of these three cases:
   1) eval "var_$suffix=value" (there are 36 of these)
   2) eval "[[ ... ]]"
   3) eval "(( ... ))"
Most eval'd assignments could probably be replaced with { typeset
var_$suffix=value } (sometimes adding -g).




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