Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: field splitting with empty fields



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