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 8:16 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> ... I can recapture that text from the file to a variable like this:
>
>      $ typeset -a array1=( "${(q+)$(<junk)}" )

This doesn't just "recapture" the text, it also quotes it.

>      $ print -l $array1

This unquotes the text partially before printing (because print is
invoked without -r).

> But if I try to capture the output to a variable directly:
>
>      $ array2=$(eval "$@")

This is fine. You can verify that the content is as expected:

    print -r -- $array2

Note that array2 is a scalar and not an array. array1 is an array with
one element. If you want array2 to also be an array with one element,
do this:

    array2=("$(eval "$@")")

Roman.

P.S.

Use `typeset -p var` to see the value of parameter `var`.

    typeset -p array2




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