In bash
, there is a parameter expansion to generate the names of variables matching a given prefix. For example:
$ foo1=a foo2=b four=4
$ echo "${!foo@}"
foo1 foo2
Is there an equivalent in zsh
? I know the (P)
parameter expansion flag is the equivalent of the similar bash
indirection expansion ${!foo}
:
# bash
$ foo=bar bar=3
$ echo ${!foo}
3
# zsh
% foo=bar bar=3
% echo ${(P)foo}
3
but as far as I can tell, (P)
does not also handle prefix matching.
% echo "${(P}foo@}"
zsh: bad substitution
There doesn't seem to be any way to perform any type of globbing on a parameter name, only on the expansion of a parameter.
(This seems to be a necessary precursor for a solution for "Use wildcard expansion to echo all variables in zsh", though I could be mistaken about that.)
parameters
being defined, though couldn't remember where I saw it. Didn't see it inman zshparams
, so thought I had imagined it. – Reflect