Get list of variables whose name matches a certain pattern
Use the builtin command compgen:
compgen -A variable | grep X
Easiest might be to do a
printenv |grep D.*=
The only difference is it also prints out the variable's values.
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.*"