获取名称与特定模式匹配的变量列表 [英] Get list of variables whose name matches a certain pattern

查看:67
本文介绍了获取名称与特定模式匹配的变量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以bash

echo ${!X*}

将打印名称以'X'开头的变量的所有名称.
是否有可能以任意模式获得相同的结果,例如获取变量名称在任何位置都包含"X"的所有名称?

will print all the names of the variables whose name starts with 'X'.
Is it possible to get the same with an arbitrary pattern, e.g. get all the names of the variables whose name contains an 'X' in any position?

推荐答案

使用内置命令compgen:

Use the builtin command compgen:

compgen -A variable | grep X

这篇关于获取名称与特定模式匹配的变量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆