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

Re: Question on array processing.



In the last episode (Oct 04), Larry P. Schrof said:
> There is a subscript flag, s:<string> , (used with the 'w' flag) that
> allows you to index into a string as if it were an array, using
> <string> as a separator for elements.
> 
> Here's my question:
> 
> I absolutely can NOT figure out how to get zsh to use a single colon
> (':') as a separator. No matter how I try to quote the second colon,
> zsh sees the second colon in the expression as the termination for
> the separator string.
> 
> I'm tring to do something like:
> 
> > str="these:are:some:words"
> > echo ${str[(ws:::)2]}
> zsh: bad math expression: operand expected at `::)2'
> 
> I've also tried :":":, :\::, and :':': - none of those work.
> 
> Is this a small flaw / hole in zsh's functionality?

You can use any character as a delimiter, not just a colon:

$ str="these:are:some:words"
$ echo ${str[(ws/:/)2]}
are

-- 
	Dan Nelson
	dnelson@xxxxxxxxxxxxxxx



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