Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mix and match parameter expansion flags and sub-scripting flags + quoting



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