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

Re: Word split



On Nov 6,  4:49pm, Bernd Eggink wrote:
} Subject: Word split
}
} 	x='a::b'
} 	y=(${(s(:)x})
                  ^
        y=(${(s(:))x})
                  ^
} I wanted $y to hold 3 elements, with an empty $y[2], but the result is
} an array with 2 elements, 'a' and 'b'. This would be OK if at least 
} 
} 	y=("${(@s(:)x}")
                    ^
  	y=("${(@s(:))x}")
                    ^
} gave 3 elements, but it doesn't either.

I thought perhaps this was a problem with using it in the array context,
but ${(ws(:))#x} yeilds 2, so it really is dropping the empty word when
doing the split.

While we're on the subject, is there any chance the manual could get some
more examples added to the parameter expansion section?  It's really not
very easy to understand from the one-line descriptions what something like
${(SI(1)B)x%:} will produce.

"Include the index of the beginning of the match in the result."

Whaddaya mean, "include?"

Well, what you mean is that if you use multiple flags, you get multiple
words in the result:

    zagzig[144] echo ${(SI(1)BE)x%:}
    3 4

But the order of the flags doesn't make any difference:

    zagzig[145] echo ${(SI(1)EB)x%:}
    3 4

And nowhere is it explained what order they're going to show up in:

    zagzig[146] echo ${(SI(1)BR)x%:}
    a:b 3
    zagzig[147] echo ${(SI(1)MR)x%:}
    : a:b
    zagzig[148] echo ${(SI(1)RBM)x%:}
    : a:b 3
    zagzig[149] echo ${(SI(1)RBMN)x%:}
    : a:b 3 1
    zagzig[150] echo ${(SI(1)RBMNE)x%:}
    : a:b 3 4 1

Lots of zsh's features lurk behind this kind of veil of semidocumentation.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author