Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: array with newlines preserved as literal text
- X-seq: zsh-users 26450
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- 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 20:26:56 +0100
- Archived-at: <https://zsh.org/users/26450>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/CAN%3D4vMoYjExx9Oq8%3DL68ygrE6UHniqRqEm1csh7_SwscqZJmHA%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 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