TL; DR: is there a zsh
equivalent of Ksh/Bash's "${!varnamepfx@}"
expansion?
So that, for example, if I have the following variables set
:
[...]
foo='random value'
bar=$'amazing\n value'
baz='that other value'
[...]
then by requesting printf -- %s\\n "${!ba@}"
in Bash I get:
bar
baz
I've been perusing the zsh
manual but haven't been able to find anything direct like the above syntax. The best I could resort to has been the following nested-expansion:
(for the example above)
printf -- %s\\n "${(M)${${(f)$(set)}[@]%%=*}[@]:#ba*}"
It seems to be doing the job reliably (at least on MacOS Catalina's zsh v5.3) but looks quite convoluted and I also wonder whether the $(set)
Command Substitution in there really spawns a process or is instead optimized by zsh
.
Admittedly, I have so far ruled out (and thus not looked into) getting that job done through the Completion System as it would seem a bit of an overkill for such a simple task.