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

标签 zsh variable-expansion

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

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/

相关文章:

bash - 从包含路径的变量中删除当前目录

java - 替换文本: Suggestions?中的变量

bash - 带变量的括号扩展?

bash - 当 POSIX 规范说有必要避免歧义时,它是什么意思?

unix - 在 zsh 中取消全局别名的别名

bash - 如何在保持流分离的同时将 stdout+stderr 重定向到一个文件?

docker - 为什么 zsh alias 不能正确评估嵌套命令?

video - 使用 zsh 和 ffmpeg 从嵌套目录中的视频递归生成静止图像

linux - Bash - 命令和变量扩展

batch-file - .BAT 文件中的 %0 不正确