Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: reading a file into an array. mapfile? (f)?
- X-seq: zsh-users 13251
- From: Peter Stephenson <pws@xxxxxxx>
- To: "zsh users mailing list" <zsh-users@xxxxxxxxxx>
- Subject: Re: reading a file into an array. mapfile? (f)?
- Date: Fri, 19 Sep 2008 10:07:25 +0100
- In-reply-to: <6cd6de210809181747kc0f0a5bt4489f534589725a8@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <6cd6de210809171953pd956d75gd4b3609ac036fe0@xxxxxxxxxxxxxx> <080917214418.ZM27616@xxxxxxxxxxxxxxxxxxxxxx> <6cd6de210809181747kc0f0a5bt4489f534589725a8@xxxxxxxxxxxxxx>
On Thu, 18 Sep 2008 20:47:00 -0400
"Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> wrote:
> On Thu, Sep 18, 2008 at 12:44 AM, Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx>wrote:
> > It's much simpler than you seem to believe:
> >
> > lines=( ${(f)mapfile[/path/to/file]} )
>
>
> Doesn't seem to work if the file (/path/to/file) has 0-length lines. These
> don't get stored in the array (lines).
Try
lines=( "${(f)mapfile[/path/to/file]}" )
Explanation: without the quotes, elements that turn into an empty string
are removed. (f) includes the effect of the (@) flag, which is a
generalised equivalent of the behaviour of "${array[@]}", so simply adding
the quotes is enough to get the empty lines.
I'd better update the change I made to the mapfile documentation.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author