Get list of variables whose name matches a certain pattern

后端 未结 5 554
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 09:21

In bash

echo ${!X*}

will print all the names of the variables whose name starts with \'X\'.
Is it possible to get the same with an ar

5条回答
  •  半阙折子戏
    2020-12-13 09:39

    This should do it:

    env | grep ".*X.*"
    

    Edit: sorry, that looks for X in the value too. This version only looks for X in the var name

    env | awk -F "=" '{print $1}' | grep ".*X.*"
    

    As Paul points out in the comments, if you're looking for local variables too, env needs to be replaced with set:

    set | awk -F "=" '{print $1}' | grep ".*X.*"
    

提交回复
热议问题