* Question on array processing.
@ 2006-10-04 20:00 Larry P. Schrof
2006-10-04 20:07 ` Dan Nelson
0 siblings, 1 reply; 5+ messages in thread
From: Larry P. Schrof @ 2006-10-04 20:00 UTC (permalink / raw)
To: zsh-users
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?
Thanks.
- Larry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on array processing.
2006-10-04 20:00 Question on array processing Larry P. Schrof
@ 2006-10-04 20:07 ` Dan Nelson
2006-10-04 20:10 ` Dan Nelson
2006-10-04 20:18 ` Larry P. Schrof
0 siblings, 2 replies; 5+ messages in thread
From: Dan Nelson @ 2006-10-04 20:07 UTC (permalink / raw)
To: Larry P. Schrof; +Cc: zsh-users
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@allantgroup.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on array processing.
2006-10-04 20:07 ` Dan Nelson
@ 2006-10-04 20:10 ` Dan Nelson
2006-10-04 20:20 ` Larry P. Schrof
2006-10-04 20:18 ` Larry P. Schrof
1 sibling, 1 reply; 5+ messages in thread
From: Dan Nelson @ 2006-10-04 20:10 UTC (permalink / raw)
To: Larry P. Schrof; +Cc: zsh-users
In the last episode (Oct 04), Dan Nelson said:
> In the last episode (Oct 04), Larry P. Schrof said:
> > 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
Forgot to include the documentation that mentions this:
The following flags (except p) are followed by one or more
arguments as shown. Any character, or the matching pairs
`(...)', `{...}', `[...]', or `<...>', may be used in place of a
colon as delimiters, but note that when a flag takes more than
one argument, a matched pair of delimiters must surround each
argument.
--
Dan Nelson
dnelson@allantgroup.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on array processing.
2006-10-04 20:07 ` Dan Nelson
2006-10-04 20:10 ` Dan Nelson
@ 2006-10-04 20:18 ` Larry P. Schrof
1 sibling, 0 replies; 5+ messages in thread
From: Larry P. Schrof @ 2006-10-04 20:18 UTC (permalink / raw)
To: Dan Nelson; +Cc: zsh-users
Awesome - thanks!
Huge favor - could the zshparam man page please be updated to
reflect this? I didn't see anything about it in the subscript flags section.
Also, while I'm requesting updates to the man page, I wanted to point
out a couple of typos I found if anybody wants to correct them.
On the zshparams man page, under the subscript flags section, there is
an identical typo that appears twice:
On the first line of both the 'w' and 'f' subscript flags, the text reads:
"If the parameter subscripted is a scalar than this flag makes"
The 'than' should probably be 'then'. Sorry to be anal. ;)
- Larry
On Wed, Oct 04, 2006 at 03:07:59PM -0500, Dan Nelson wrote:
> 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@allantgroup.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on array processing.
2006-10-04 20:10 ` Dan Nelson
@ 2006-10-04 20:20 ` Larry P. Schrof
0 siblings, 0 replies; 5+ messages in thread
From: Larry P. Schrof @ 2006-10-04 20:20 UTC (permalink / raw)
To: Dan Nelson; +Cc: zsh-users
> Forgot to include the documentation that mentions this:
>
> The following flags (except p) are followed by one or more
> arguments as shown. Any character, or the matching pairs
> `(...)', `{...}', `[...]', or `<...>', may be used in place of a
> colon as delimiters, but note that when a flag takes more than
> one argument, a matched pair of delimiters must surround each
> argument.
I didn't see anything about this in zshparams specificially. Would it
be worth mentioning there as well?
Thanks again.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-10-04 20:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-04 20:00 Question on array processing Larry P. Schrof
2006-10-04 20:07 ` Dan Nelson
2006-10-04 20:10 ` Dan Nelson
2006-10-04 20:20 ` Larry P. Schrof
2006-10-04 20:18 ` Larry P. Schrof
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).