echo names and values of all env variables that start with ânlu_settingâ
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-1
down vote
favorite
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?
bash shell shell-indirection indirection
add a comment |Â
up vote
-1
down vote
favorite
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?
bash shell shell-indirection indirection
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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?
bash shell shell-indirection indirection
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?
bash shell shell-indirection indirection
asked 2 days ago
Alexander Mills
1,834929
1,834929
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago
add a comment |Â
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done
The expansion $!nlu_setting@
is a bash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_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
).
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not callinggrep
. Your solution would also pick up variable names that containnlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
add a comment |Â
up vote
0
down vote
After looking at the answers to this question, I came up with this:
compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done
it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done
The expansion $!nlu_setting@
is a bash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_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
).
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not callinggrep
. Your solution would also pick up variable names that containnlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
add a comment |Â
up vote
2
down vote
accepted
for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done
The expansion $!nlu_setting@
is a bash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_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
).
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not callinggrep
. Your solution would also pick up variable names that containnlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done
The expansion $!nlu_setting@
is a bash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_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
).
for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done
The expansion $!nlu_setting@
is a bash
-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_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
).
edited 2 days ago
answered 2 days ago
Kusalananda
100k13199311
100k13199311
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not callinggrep
. Your solution would also pick up variable names that containnlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
add a comment |Â
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not callinggrep
. Your solution would also pick up variable names that containnlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
do you think this is better than the compgen solution?
â Alexander Mills
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not calling
grep
. Your solution would also pick up variable names that contain nlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).â Kusalananda
2 days ago
@AlexanderMills I would say that it will be more efficient as it's not calling
grep
. Your solution would also pick up variable names that contain nlu_setting_
anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).â Kusalananda
2 days ago
ah yes good point
â Alexander Mills
2 days ago
ah yes good point
â Alexander Mills
2 days ago
add a comment |Â
up vote
0
down vote
After looking at the answers to this question, I came up with this:
compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done
it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..
add a comment |Â
up vote
0
down vote
After looking at the answers to this question, I came up with this:
compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done
it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..
add a comment |Â
up vote
0
down vote
up vote
0
down vote
After looking at the answers to this question, I came up with this:
compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done
it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..
After looking at the answers to this question, I came up with this:
compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done
it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..
answered 2 days ago
Alexander Mills
1,834929
1,834929
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460462%2fecho-names-and-values-of-all-env-variables-that-start-with-nlu-setting%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
â JdeBP
2 days ago