Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: field splitting with empty fields
- X-seq: zsh-users 12144
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: field splitting with empty fields
- Date: Tue, 30 Oct 2007 11:58:27 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <20071030104459.562a77b1@news01>
- Mail-followup-to: Peter Stephenson <pws@xxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20071029235835.GA29356@xxxxxxxxxxx> <071029171355.ZM28438@xxxxxxxxxxxxxxxxxxxxxx> <20071030042048.GA32506@xxxxxxxxxxx> <20071030104459.562a77b1@news01>
On Tue, Oct 30, 2007 at 10:44:59AM +0000, Peter Stephenson wrote:
> On Tue, 30 Oct 2007 00:20:48 -0400
> Clint Adams <clint@xxxxxxx> wrote:
> > On Mon, Oct 29, 2007 at 05:13:55PM -0700, Bart Schaefer wrote:
> > > print ${list//:/$'\n'}
> > >
> > > ??
> >
> > Okay, I asked a stupid question.
> >
> > I want the line split into words according to fields which may be
> > blank. Right now I'm substituting :x: for :: and then removing
> > the x's to ensure that the array value match up to the proper
> > indices. This seems suboptimal.
>
> It's odd it removes the space even if quoted:
>
> % foo="one:two::four:five"
> % print -l "${(@s.:.)foo}"
> one
> two
> four
> five
[...]
Hi Peter,
I've always known it to behave like that, I even thought it was
documented but I can't find it now in the manual so maybe it
wasn't.
I've myself already relied on it before, though many other
times, it's true I have wished it was not removing empty items.
${(f)var}
strips the empty lines.
If you want to retain empty items, you can always use IFS.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author