In bash, how do I list environment variables matching “MY_VAR” and then export them?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to export all environment variables beginning with "MY_VAR_".
How do I do this?
bash environment-variables
New contributor
add a comment |
up vote
0
down vote
favorite
I want to export all environment variables beginning with "MY_VAR_".
How do I do this?
bash environment-variables
New contributor
1
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to export all environment variables beginning with "MY_VAR_".
How do I do this?
bash environment-variables
New contributor
I want to export all environment variables beginning with "MY_VAR_".
How do I do this?
bash environment-variables
bash environment-variables
New contributor
New contributor
edited Nov 20 at 20:13
Rui F Ribeiro
38.2k1475125
38.2k1475125
New contributor
asked Nov 20 at 17:00
virasana
1
1
New contributor
New contributor
1
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03
add a comment |
1
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03
1
1
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
As export
of an already exported variable is no-op:
export "$!MY_VAR_@"
Will export all variables that start with MY_VAR_
.
If you only want the list of exported variables that start with MY_VAR_
:
env | grep '^MY_VAR_'
Or (calling an external program only keeps exported variables):
bash -c 'printf %s\n "$!MY_VAR_@"'
Or, if you have completion
available (it is loaded by default):
$ compgen -A export MY_VAR_
MY_VAR_aa
MY_VAR_bb
MY_VAR_ss
how aboutsh -c 'echo $!MY_VAR_@'
for listing exported variables that start withMY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work ifsh
is linked tobash
and better that you quote the expansion of the variable:bash -c 'printf %s\n "$!MY_VAR_@"'
.
– Isaac
Nov 21 at 4:58
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
As export
of an already exported variable is no-op:
export "$!MY_VAR_@"
Will export all variables that start with MY_VAR_
.
If you only want the list of exported variables that start with MY_VAR_
:
env | grep '^MY_VAR_'
Or (calling an external program only keeps exported variables):
bash -c 'printf %s\n "$!MY_VAR_@"'
Or, if you have completion
available (it is loaded by default):
$ compgen -A export MY_VAR_
MY_VAR_aa
MY_VAR_bb
MY_VAR_ss
how aboutsh -c 'echo $!MY_VAR_@'
for listing exported variables that start withMY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work ifsh
is linked tobash
and better that you quote the expansion of the variable:bash -c 'printf %s\n "$!MY_VAR_@"'
.
– Isaac
Nov 21 at 4:58
add a comment |
up vote
4
down vote
As export
of an already exported variable is no-op:
export "$!MY_VAR_@"
Will export all variables that start with MY_VAR_
.
If you only want the list of exported variables that start with MY_VAR_
:
env | grep '^MY_VAR_'
Or (calling an external program only keeps exported variables):
bash -c 'printf %s\n "$!MY_VAR_@"'
Or, if you have completion
available (it is loaded by default):
$ compgen -A export MY_VAR_
MY_VAR_aa
MY_VAR_bb
MY_VAR_ss
how aboutsh -c 'echo $!MY_VAR_@'
for listing exported variables that start withMY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work ifsh
is linked tobash
and better that you quote the expansion of the variable:bash -c 'printf %s\n "$!MY_VAR_@"'
.
– Isaac
Nov 21 at 4:58
add a comment |
up vote
4
down vote
up vote
4
down vote
As export
of an already exported variable is no-op:
export "$!MY_VAR_@"
Will export all variables that start with MY_VAR_
.
If you only want the list of exported variables that start with MY_VAR_
:
env | grep '^MY_VAR_'
Or (calling an external program only keeps exported variables):
bash -c 'printf %s\n "$!MY_VAR_@"'
Or, if you have completion
available (it is loaded by default):
$ compgen -A export MY_VAR_
MY_VAR_aa
MY_VAR_bb
MY_VAR_ss
As export
of an already exported variable is no-op:
export "$!MY_VAR_@"
Will export all variables that start with MY_VAR_
.
If you only want the list of exported variables that start with MY_VAR_
:
env | grep '^MY_VAR_'
Or (calling an external program only keeps exported variables):
bash -c 'printf %s\n "$!MY_VAR_@"'
Or, if you have completion
available (it is loaded by default):
$ compgen -A export MY_VAR_
MY_VAR_aa
MY_VAR_bb
MY_VAR_ss
edited Nov 21 at 5:02
answered Nov 20 at 17:23
Isaac
9,70411445
9,70411445
how aboutsh -c 'echo $!MY_VAR_@'
for listing exported variables that start withMY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work ifsh
is linked tobash
and better that you quote the expansion of the variable:bash -c 'printf %s\n "$!MY_VAR_@"'
.
– Isaac
Nov 21 at 4:58
add a comment |
how aboutsh -c 'echo $!MY_VAR_@'
for listing exported variables that start withMY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work ifsh
is linked tobash
and better that you quote the expansion of the variable:bash -c 'printf %s\n "$!MY_VAR_@"'
.
– Isaac
Nov 21 at 4:58
how about
sh -c 'echo $!MY_VAR_@'
for listing exported variables that start with MY_VAR_
– iruvar
Nov 21 at 4:48
how about
sh -c 'echo $!MY_VAR_@'
for listing exported variables that start with MY_VAR_
– iruvar
Nov 21 at 4:48
@iruvar That will only work if
sh
is linked to bash
and better that you quote the expansion of the variable: bash -c 'printf %s\n "$!MY_VAR_@"'
.– Isaac
Nov 21 at 4:58
@iruvar That will only work if
sh
is linked to bash
and better that you quote the expansion of the variable: bash -c 'printf %s\n "$!MY_VAR_@"'
.– Isaac
Nov 21 at 4:58
add a comment |
virasana is a new contributor. Be nice, and check out our Code of Conduct.
virasana is a new contributor. Be nice, and check out our Code of Conduct.
virasana is a new contributor. Be nice, and check out our Code of Conduct.
virasana is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483011%2fin-bash-how-do-i-list-environment-variables-matching-my-var-and-then-export-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The variables whose names begin with that, or the variables whose values begin with that? Also, do you mean environment variables (exported shell variables) in particular, or just all shell variables?
– ilkkachu
Nov 20 at 17:05
Environment variables are already exported. What do want to achieve in the end?
– Kusalananda
Nov 21 at 8:03