变量输出的通配符
我有以下变量的列表:
abc1=1
abc2=2
qwerty=4
qwerty3=3
abc9=9
是否可以以某种方式输出以 abc 开头的所有变量的值?
类似通配符的东西: printf "%s\n" "${abc*}"
I have a list of the following variables:
abc1=1
abc2=2
qwerty=4
qwerty3=3
abc9=9
Is it possible somehow to output the value of all variables that begin with abc
?
Something like wildcard: printf "%s\n" "${abc*}"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点脆弱,但
基本上会做您问的事情。
来自
set
的输出包括功能定义;功能体将被缩进,因此它们与GREP
模式不匹配。如果您还想排除名称以abc
开头的函数的名称,也许只需添加| grep -vf'()'
;或重构略复杂的sed
脚本:如果您想打印功能及其身体,则可能也可以在
sed
或awk中完成。It is somewhat brittle, but
will basically do what you ask.
The output from
set
includes function definitions; the function bodies will be indented, so they won't match thegrep
pattern. If you also want to exclude the names of functions whose names begin withabc
, maybe simply add| grep -vF '()'
; or refactor to a slightly more complexsed
script:If you wanted to print functions along with their bodies, that too could probably done in
sed
or Awk.