使用通配符扩展来回显zsh中的所有变量 [英] Use wildcard expansion to echo all variables in zsh
问题描述
在以相同模式开头的多个变量中,可以使用通配符来回显所有匹配的模式吗?
With multiple variables beginning with the same pattern can a wildcard be used to echo all matched patterns?
zzz1=test1; zzz_A=test2; zzza=test3
匹配以zzz开头的所有变量的最佳方法是什么. echo $zzz*
或for i in $zzz*; do echo $i; done
之类的内容将输出:
What is the best way to match all variables starting with zzz. Where something like echo $zzz*
or for i in $zzz*; do echo $i; done
would output:
test1
test2
test3
推荐答案
因此,要根据上面的评论直接回答...否,zsh无法使用通配符扩展和回显变量,但是typeset
可以提供所需的结果.
So to directly answer based on comments above... No, zsh cannot expand and echo variables using a wildcard, but typeset
can provide the desired result.
typeset -m 'zzz*'
输出:
zzz_A=test2
zzz1=test1
zzza=test3
或更准确地得到我想要的输出,如此处所述:
or more accurately to get my desired output as explained 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
这篇关于使用通配符扩展来回显zsh中的所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!