使用通配符扩展来回显 zsh 中的所有变量

Use wildcard expansion to echo all variables in zsh

对于以相同模式开头的多个变量,是否可以使用通配符来回应所有匹配的模式?

zzz1=test1; zzz_A=test2; zzza=test3

匹配所有以 zzz 开头的变量的最佳方法是什么。 echo $zzz*for i in $zzz*; do echo $i; done 之类的内容会输出:

test1
test2
test3

所以根据上面的评论直接回答...不,zsh 不能使用通配符扩展和回显变量,但是 typeset 可以提供所需的结果。

typeset -m 'zzz*' 输出:

zzz_A=test2
zzz1=test1
zzza=test3

或更准确地得到我想要的输出,如here所述:

for i in `typeset +m 'zzz*'`; do echo "${i}:  ${(P)i}"; done
zzz1:  test1
zzz_A:  test2
zzza:  test3

或者只是...

for i in `typeset +m 'zzz*'`; do echo "${(P)i}"; done
test1
test2
test3