Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Mix and match parameter expansion flags and sub-scripting flags + quoting
- X-seq: zsh-users 23044
- From: dana <dana@xxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Subject: Re: Mix and match parameter expansion flags and sub-scripting flags + quoting
- Date: Mon, 1 Jan 2018 02:27:08 -0600
- Cc: zsh <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mJ1cuG2NWM8eUfeRsW3wqSMr2Uns0eCSsHI786YsyIQ=; b=pfi1VEKGyCUKkEf8DFF6mI3zZmujWc0Q7iiv+T20II4bF4sSoHcRC0B582HOwJoT5s JoEOIpYKaFvQ+QwhccEQ/lOtboEyFQ7C/70RR8fU5GQcocIUMCdXkT7viZMaVXcPlm8D dRt6Jy7/ELNH2JJQqJtm1RrowCguZctbjW+VZdHjpMi65vUDvvd6ydXSuPxVNOsTr6fn eYreLNVEmDSH/ROUzo4ioy0Ege+lEvMpZ1U/tdK1hvR2u90CIcO5k8es0wVxYpoGXqeH TPCP20EEdk70Z84GJqXvGf/JBc1z+A+aUPm5/0XWhlwSFFYSa0qp4KJeZvNYATah3Yj3 HSsg==
- In-reply-to: <CA+rB6GJoUdjh9ync9LdbMMszDyCuOF2_wXN9sVOvzEzfQcvwuQ@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CA+rB6GLSgUkWiBRMmNQ_gc-A2pABpPJVnR8xf9tpYaK3e8JMyQ@mail.gmail.com> <CAH+w=7bC2D+n8t-8UwD0Q++4mg98JvsJpYMmU0iC=yqr8ozWOQ@mail.gmail.com> <CA+rB6GJoUdjh9ync9LdbMMszDyCuOF2_wXN9sVOvzEzfQcvwuQ@mail.gmail.com>
On 31 Dec 2017, at 13:01, Jim <linux.tech.guy@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author