Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: lines to array
- X-seq: zsh-users 11194
- From: Meino Christian Cramer <Meino.Cramer@xxxxxx>
- To: pws@xxxxxxx
- Subject: Re: lines to array
- Date: Wed, 14 Feb 2007 17:54:25 +0100 (CET)
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <20070214112820.b115e849.pws@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <17393e3e0702132143v36772365j179fff0f77cd6f@xxxxxxxxxxxxxx> <14989d6e0702132345yecd64f9xdaf474f1d3bf85ec@xxxxxxxxxxxxxx> <20070214112820.b115e849.pws@xxxxxxx>
From: Peter Stephenson <pws@xxxxxxx>
Subject: Re: lines to array
Date: Wed, 14 Feb 2007 11:28:20 +0000
Hi,
thanks a lot for the code and its explanation! :)
One additional question: Is there a zshy way to sort
the array and throw away any doubled entry ?
Happy zshing!
mcc
> "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