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

Bug / error in manpage.



I have found an error in the manpage, or incomplete functionality -
whatever you'd like to call it.

If you are new to zsh and want to learn a couple of things, read
on. If you are a veteran and just want to read about the bug,
jump to the string '===' below in this email.

Context

Let's say I have a string that contains words separated by some
arbitrary token. I'll pick a line from /etc/passwd:

zsh% string=$(grep '^nobody' /etc/passwd)

$() is the same as backticks, but better.

zsh% print $string
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false

Let's say we want to get the value of the second field.
Let's try something naive:

zsh% print $string[2]
o
zsh%

That doesn't work - by default it indexes on characters if
it's a scalar. Let's use the split-on-word flag:

zsh% print $string[(w)2]
User:/var/empty:/usr/bin/false

Nope - that's not what we want. It split on whitespace.
We want to tell it to split on colons:

zsh% print $string[(ws{:})2]
*
zsh%

Excellent that's what we want!

===
The man page for subscripting flags is incorrect. Here is the excerpt:

       The flags s, n and b take an argument; the delimiter is shown below  as
       `:',  but  any  character,  or  the  matching  pairs  `(...)', `{...}',
       `[...]', or `<...>', may be used.

The '< >' brackets do not work as separators:
zsh% print $string[(ws<:>)2]
zsh: parse error near `)'
zsh%

This is exactly like the previous command, except the curly braces were changed
to arrow brackets.

Can we either update the manpage, removuing mention of '<...>', or add the ability
to parse them?

Thanks!
===



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