I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:
nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo
does anyone know how to do this?
bashenvironment-variablesshellvariable
I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:
nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo
does anyone know how to do this?
Best Answer
The expansion
${!nlu_setting_@}
is abash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to ask for all names that start with the stringnlu_setting_
. We loop over these names and output the name along with the value of that variable.We get the value of the variable using variable indirection (
${!var}
).