From: dana <dana@dana.is>
To: linuxtechguy@gmail.com
Cc: zsh <zsh-users@zsh.org>
Subject: Re: Mix and match parameter expansion flags and sub-scripting flags + quoting
Date: Mon, 1 Jan 2018 02:27:08 -0600 [thread overview]
Message-ID: <428FD648-763F-4B02-9CB7-3E91746261A8@dana.is> (raw)
In-Reply-To: <CA+rB6GJoUdjh9ync9LdbMMszDyCuOF2_wXN9sVOvzEzfQcvwuQ@mail.gmail.com>
On 31 Dec 2017, at 13:01, Jim <linux.tech.guy@gmail.com> wrote:
>The question, for me, is why two different results, by the same subscript,
>to
>apparently the same output from each type of match?
In both cases, ${(f)...} is giving you an array. But...
>shell=${${(M)"${(f)"$(<${TestFile})"}":#*:${UID}:${GID}:*}[(ws/:/)7]} ;
In this case, ${(M)...:#...} is giving you another array consisting of the
members of the first one that match the pattern. Your subscript [(ws/:/)7]
doesn't work, then, because as the documentation says...
>w
>If the parameter subscripted is a scalar then this flag makes subscripting work
>on words instead of characters.
The parameter is *not* a scalar (yet), so it has no effect; it's just ignored.
The subscript then is functionally equivalent to [7], and since there is no
index 7 in the array of matches that gives an empty string.
>shell=${${"${(f)"$(<${TestFile})"}"[(r)*:${UID}:${GID}:*]}[(ws/:/)7]} ;
In this case, ${...[(r)...]} is returning the first (and only the first) element
that matches the pattern. Since that element is a scalar, the (w) subscript flag
works the way you want.
dana
prev parent reply other threads:[~2018-01-01 8:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-29 15:29 Jim
2017-12-29 18:43 ` Bart Schaefer
2017-12-31 19:01 ` Jim
2018-01-01 8:27 ` dana [this message]
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=428FD648-763F-4B02-9CB7-3E91746261A8@dana.is \
--to=dana@dana.is \
--cc=linuxtechguy@gmail.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).