The following works with or w/o the "external" quotes:
shell="${${${(f)"$(<${TestFile})"}[(r)*:${UID}:${GID}:*]}[(ws/:/)7]}"
as does:
shell="${${(s/:/)"${(f)"$(<${TestFile})"}"[(r)${USER}:*]}[-1]}"
The following returns the correct result, only if there are no
"external" quotes(as shown):
shell=${${(s/:/)${(M)"${(f)$(<${TestFile})}":#${USER}:*}}[-1]}
Would like to understand what is going on here when "external"
quotes a present.
The following does not produce any errors, but it also doesn't return
the intended output, with or w/o "external" quotes:
shell="${${(M)${(f)"$(<${TestFile})"}:#*:${UID}:${GID}:*}[(ws/:/)-1]}"
I thought this was the proper use of zsh tools, but since it isn't
returning the intended results, it must be incorrect. Any thoughts
on what I am doing wrong and or assumptions made?
Also, depending on patterns, subscripts, and in one known case, quoting;
the results returned are all over the place. It could be a "blank line",
or the last field of the last line of the passwd file, or the last field
of the first line + the first field of the second line, or the entire
line for $USER.
Note, if your USER entry is the last line of the passwd file, you can
get the correct results, even though the code is wrong. Found this the
hard way.
Any pointers as to how to proceed to understand what is going on would
be appreciated. Thanks in advance.
My distributions currently distributes ZSH_VERSION 5.3.1.
Sincerely,
Jim
P.S. The attached script shows the variations I've tried.
I don't expect anyone to fix any incorrect scripting,
that's on me.