From: Larry Schrof <larrys@fb.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Bug / error in manpage.
Date: Mon, 1 Oct 2012 18:08:36 +0000 [thread overview]
Message-ID: <CC8F2A37.9567%larrys@fb.com> (raw)
[-- 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!
===
next reply other threads:[~2012-10-01 18:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-01 18:08 Larry Schrof [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CC8F2A37.9567%larrys@fb.com \
--to=larrys@fb.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).