Hello friendly guys. On Linux with Bash, I often need to list environment variables(env-var) whose names start with some predefined word. For example, to list all env-vars with name pattern gmXXX, I will do
[chj @linux-ic37 ~]$ export|grep '^declare -x gm'
declare -x gmu_DO_SHOW_COMPILE_CMD="1"
declare -x gmu_DO_SHOW_LINK_CMD="1"
But writing that long command everytime is boring. So, can I write an alias to simplify it? I tried but no luck.
[chj @linux-ic37 ~]$ alias fvgm="export|grep \'^declare -x gm\'"
[chj @linux-ic37 ~]$ fvgm
grep: gm': No such file or directory
Can anyone help me out?
To make it further, can I go as far as having ‘gm’ parameterized, like
fv gm
to list all env-var starting with ‘gm’ ?
You don’t need to escape the single-quote in your alias. Change it to:
You need to write a function to make it generic. For example:
You can then call: