zsh-users
 help / color / mirror / code / Atom feed
* Bug / error in manpage.
@ 2012-10-01 18:08 Larry Schrof
  2012-10-02 11:57 ` Peter Stephenson
  2012-10-02 14:06 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Larry Schrof @ 2012-10-01 18:08 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1668 bytes --]

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!
===


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-10-02 20:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-01 18:08 Bug / error in manpage Larry Schrof
2012-10-02 11:57 ` Peter Stephenson
2012-10-02 14:06 ` Bart Schaefer
2012-10-02 17:40   ` Larry Schrof
2012-10-02 18:35   ` Peter Stephenson
2012-10-02 18:39     ` Larry Schrof
2012-10-02 20:00       ` Peter Stephenson

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).