Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: lines to array
- X-seq: zsh-users 11193
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: lines to array
- Date: Wed, 14 Feb 2007 11:28:20 +0000
- In-reply-to: <14989d6e0702132345yecd64f9xdaf474f1d3bf85ec@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Cambridge Silicon Radio
- References: <20070214.050256.41196704.Meino.Cramer@xxxxxx> <17393e3e0702132143v36772365j179fff0f77cd6f@xxxxxxxxxxxxxx> <14989d6e0702132345yecd64f9xdaf474f1d3bf85ec@xxxxxxxxxxxxxx>
"Christian Walther" <cptsalek@xxxxxxxxx> wrote:
> On 14/02/07, Matt Wozniski <godlygeek@xxxxxxxxx> wrote:
> > array=( "${(f)$(ls -l)}" )
>
> Could you please explain what ${(f)...} actually does? Is there some
> kind of parameter expansion going on?
Yes, the effect of (f) is described in "Parameter Expansion Flags" in the
zshexpn manual page. There's a hairy description below that of how nested
parmaeter expansion works. This counts as a nested parameter expansion
even though the innermost level is actually a command substitution.
This gets explained every now and then on this list, but to recap:
$(...) inside parameter is treated as a normal command substitution. The
text for enclosing parameter expansion operations is the result of the
command substitution rather than taken from a parameter. Because of the
double quotes, the command substitution produces a single word at this
point.
(f) is documented as being equivalent to (ps:\n:). The s:\n: forces the
text to be split on \n. the p interprets the \n as a newline according to
normal "print" rules.
The result is the text of "ls -l", split into lines.
You'll often see this written as
array=( ${(f)"$(ls -l)"} )
which indicates explicitly the only the command substitution is affected by
the double quotes. However, forced splitting (unlike automatic word
splitting) overrides the double quotes anyway.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
Messages sorted by:
Reverse Date,
Date,
Thread,
Author