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 13265
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh users mailing list" <zsh-users@xxxxxxxxxx>
- Subject: Re: reading a file into an array. mapfile? (f)?
- Date: Fri, 19 Sep 2008 08:19:47 -0700
- In-reply-to: <200809191100.m8JB0sAC028936@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <6cd6de210809171953pd956d75gd4b3609ac036fe0@xxxxxxxxxxxxxx> <080917214418.ZM27616@xxxxxxxxxxxxxxxxxxxxxx> <6cd6de210809181747kc0f0a5bt4489f534589725a8@xxxxxxxxxxxxxx> <20080919100725.5c471019@news01> <6cd6de210809190339g57a4e722u5ad1371e858c8501@xxxxxxxxxxxxxx> <200809191100.m8JB0sAC028936@xxxxxxxxxxxxxx>
On Sep 19, 12:00pm, Peter Stephenson wrote:
} Subject: Re: reading a file into an array. mapfile? (f)?
}
} "Rocky Bernstein" wrote:
} > Further tests show that the behavior seems to be to drop blank lines
} > but put one at the end of the file.
}
} Apologies, you're right; it seems you *do* need the @ flag, but my test
} was too simple to show it.
}
} array=("${(f@)mapfile[foo.txt]}")
}
} I'm not entirely sure why that is but I must be misremembering the (f)
} rules.
This is a fairly recent change (well, about a year ago):
For historical reasons, the usual behaviour that empty array
elements are retained inside double quotes is disabled for arrays
generated by splitting; hence the following:
line="one::three"
print -l "${(s.:.)line}"
produces two lines of output for one and three and elides the
empty field. To override this behaviour, supply the "(@)" flag as
well, i.e. "${(@s.:.)line}".
Messages sorted by:
Reverse Date,
Date,
Thread,
Author