From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: zsh-users@zsh.org
Subject: Re: Read file with escaped newlines into array
Date: Thu, 19 Nov 2015 21:14:39 +0100 [thread overview]
Message-ID: <CAKc7PVCzE_FXpak715BtDnR5KPGF8airXtXK61qJzokz5yuF4g@mail.gmail.com> (raw)
In-Reply-To: <151119111749.ZM8874@torch.brasslantern.com>
On 19 November 2015 at 20:17, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Nov 19, 6:34pm, Sebastian Gniazdowski wrote:
> }
> } fc -W stores history to a given file. It escapes newlines with \. How
> } to read such file into array and have "\^M" lines put back together
> } into single array entries?
>
> The best way is probably to use the history mechanism to read it:
>
> () { fc -ap -R the_given_file ; the_desired_array=( ${history} ) }
>
> Although the docs don't yet say so, the special associative array
> $history is not implemented as a hash table, so the entries are
> guaranteed to be in a fixed order from most recent (largest history
> number) to longest ago. Which is the reverse of the way you'd read
> them from the file, so you might want ${(Oa)the_desired_array} when
> referencing.
The way $history is implemented is crucial to me and solves my
problem. I needed ordered history started from most recent, without
"\n" substituted for newlines, and "$history[@]" does that. Thanks.
This could be mentioned in documentation just to protect that
functionality
Best regards,
Sebastian Gniazdowski
next prev parent reply other threads:[~2015-11-19 20:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-19 17:34 Sebastian Gniazdowski
2015-11-19 19:17 ` Bart Schaefer
2015-11-19 20:14 ` Sebastian Gniazdowski [this message]
2016-05-10 14:26 ` Sebastian Gniazdowski
2016-05-10 16:15 ` Bart Schaefer
2016-05-10 18:10 ` Sebastian Gniazdowski
2015-11-20 1:17 ` Mikael Magnusson
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=CAKc7PVCzE_FXpak715BtDnR5KPGF8airXtXK61qJzokz5yuF4g@mail.gmail.com \
--to=sgniazdowski@gmail.com \
--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).