gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:41:47 27 4
gpt4 key购买 nike

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

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

关于zsh - 使用通配符扩展来回显 zsh 中的所有变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59007726/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com