zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: array with newlines preserved as literal text
Date: Tue, 2 Feb 2021 20:26:56 +0100	[thread overview]
Message-ID: <CAN=4vMoYjExx9Oq8=L68ygrE6UHniqRqEm1csh7_SwscqZJmHA@mail.gmail.com> (raw)
In-Reply-To: <52dba8e4-2538-7c96-ecd5-66e017ab2b8e@eastlink.ca>

On Tue, Feb 2, 2021 at 8:16 PM Ray Andrews <rayandrews@eastlink.ca> 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


  reply	other threads:[~2021-02-02 19:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 19:16 Ray Andrews
2021-02-02 19:26 ` Roman Perepelitsa [this message]
2021-02-03  1:10   ` Ray Andrews
2021-02-02 20:25 ` Bart Schaefer
2021-02-02 23:31   ` Ray Andrews
2021-02-03  2:21     ` Bart Schaefer
2021-02-03 19:29       ` Ray Andrews
2021-02-03 21:19         ` Bart Schaefer
2021-02-04  2:07           ` Ray Andrews
2021-02-05  2:57             ` Bart Schaefer
2021-02-04 21:55           ` Ray Andrews
2021-02-05  3:22             ` Bart Schaefer
2021-02-05  4:17               ` Ray Andrews
2021-02-05  4:24                 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMoYjExx9Oq8=L68ygrE6UHniqRqEm1csh7_SwscqZJmHA@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).