Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: array with newlines preserved as literal text
- X-seq: zsh-users 26451
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: array with newlines preserved as literal text
- Date: Tue, 2 Feb 2021 12:25:22 -0800
- Archived-at: <https://zsh.org/users/26451>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/CAH%2Bw%3D7bAZKawy_BfTMGzuCm96NB%3DgDA6R-K9aZBd4N%2BuOOT-%3DA%40mail.gmail.com>
- In-reply-to: <52dba8e4-2538-7c96-ecd5-66e017ab2b8e@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <52dba8e4-2538-7c96-ecd5-66e017ab2b8e@eastlink.ca>
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