From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: The ~ parameter expansion flag: bug or misunderstanding
Date: Wed, 03 Sep 2014 16:14:18 +0100 [thread overview]
Message-ID: <20140903161418.3f79636b@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAKjp4B7-EeMzsXWO6O7LjPCSEhurXsCC4f2K_-cjV-5vC_h1CQ@mail.gmail.com>
On Wed, 03 Sep 2014 10:58:23 -0400
Clint Hepner <clint.hepner@gmail.com> wrote:
> I understand that you can split a parameter value on a fixed string:
>
> % print -l ${(s.1.):-a1b1c}
> a
> b
> c
>
> My reading of the ~ flag leads me to believe that you can replace the
> literal string with a pattern, so that
>
> % print -l ${(~s.[12].):-a1b2c}
> a
> b
> c
>
> However, the ~ flag seems to have no effect, with the parameter string
> remaining unsplit.
No, splitting is with (s.X.) is always on a string.
You can do something like
print -l ${(s.1.)${${:-a1b2c}//[12]/1}}
The documentation isn't very clear:
~ Force string arguments to any of the flags below that follow
within the parentheses to be treated as patterns. Compare with
a ~ outside parentheses, which forces the entire substituted
string to be treated as a pattern. Hence, for example,
[[ "?" = ${(~j.|.)array} ]]
actually means string arguments remaining after substitution are treated
as a pattern subseqeuently on the command line --- which means that it
has no effect on splitting, despite "s" being one of the flags below.
So it doesn't really say what it does in this case.
--
Peter Stephenson <p.stephenson@samsung.com> Principal Software Engineer
Tel: +44 (0)1223 434724 Samsung Cambridge Solution Centre
St John's House, St John's Innovation Park, Cowley Road,
Cambridge, CB4 0DS, UK
next prev parent reply other threads:[~2014-09-03 15:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-03 14:58 Clint Hepner
2014-09-03 15:14 ` Peter Stephenson [this message]
2014-09-04 3:18 ` Bart Schaefer
2014-09-04 19:10 ` Peter Stephenson
2014-09-03 15:44 ` Bart Schaefer
2014-09-09 16:21 ` Clint Hepner
2014-09-09 16:41 ` Peter Stephenson
2014-09-09 16:54 ` Clint Hepner
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=20140903161418.3f79636b@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@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).