From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Read file with escaped newlines into array
Date: Thu, 19 Nov 2015 11:17:49 -0800 [thread overview]
Message-ID: <151119111749.ZM8874@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>
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.
next prev parent reply other threads:[~2015-11-19 19:17 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 [this message]
2015-11-19 20:14 ` Sebastian Gniazdowski
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=151119111749.ZM8874@torch.brasslantern.com \
--to=schaefer@brasslantern.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).