Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Read file with escaped newlines into array
- X-seq: zsh-users 20968
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Read file with escaped newlines into array
- Date: Thu, 19 Nov 2015 21:14:39 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=/RFpV4/izv4pvzpyRCQDxj9g7mASusFklxPNLvZmlNU=; b=0slDJH9/nHn7ySSfHNLDHzQAY3tQNw0Pj5birUSwZk8fgHjcYcK7VKdFq4pqWOiKav 1nIGDGtbf4e86x9vSFeK+sZNVAFM9ipcEo7Y+XNWGkklvkNQLHlEESyLaJkXZ6V0q7bn GQKMKqlgNc7JWNskK9Hp8DoA+CgUdFLxHsjXd9YizLOml7GRY1xmNxoKeYFJ0WzXiuCY U4koU6vbesI1uPapqPvC1ycA7kq2Qoar9/0+Vfb+LAROx0gMCqZ9T8W7YndAHGKcbuXK cl6Va/e9r+J1rAM0uH7wyOupi+eqLAqMSoY//kmOKvvUjZHz8uW6tnQ38lC7Gv9I7B6o vf0g==
- In-reply-to: <151119111749.ZM8874@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com> <151119111749.ZM8874@torch.brasslantern.com>
On 19 November 2015 at 20:17, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author