Indirectly expand variables in shell2019 Community Moderator Electionget environment variable by variable name?In bash, how can I echo the variable value, not the variable name?How to run programs with arguments like 'arg=val' (e.g. dd) in rc shell (Linux version ported from Plan9 OS)?/: is a directory issue in bashHow can the standard input of one program be passed as an arg to another?Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)List variables with prefix where the prefix is stored in another variablePassing paths with spaces as argumentsDoes bash provide support for using pointers?Expand variables in local bash script before passing it to SSHHow can I export a variable in bash where the variable name is comprised of two variables?Why does $$# return same result as $$ in the shell?
How do I lift the insulation blower into the attic?
Reason why a kingside attack is not justified
Capacitor electron flow
Amorphous proper classes in MK
Make a Bowl of Alphabet Soup
How do you say "Trust your struggle." in French?
Travelling in US for more than 90 days
Started in 1987 vs. Starting in 1987
Trouble reading roman numeral notation with flats
Is divisi notation needed for brass or woodwind in an orchestra?
What should be the ideal length of sentences in a blog post for ease of reading?
Using an older 200A breaker panel on a 60A feeder circuit from house?
Magnifying glass in hyperbolic space
How would a solely written language work mechanically
What is the period/term used describe Giuseppe Arcimboldo's style of painting?
What is the meaning of "You've never met a graph you didn't like?"
Offset in split text content
How to test the sharpness of a knife?
Would a primitive species be able to learn English from reading books alone?
Checking @@ROWCOUNT failing
Error in master's thesis, I do not know what to do
Rendered textures different to 3D View
How do you justify more code being written by following clean code practices?
Why doesn't Gödel's incompleteness theorem apply to false statements?
Indirectly expand variables in shell
2019 Community Moderator Electionget environment variable by variable name?In bash, how can I echo the variable value, not the variable name?How to run programs with arguments like 'arg=val' (e.g. dd) in rc shell (Linux version ported from Plan9 OS)?/: is a directory issue in bashHow can the standard input of one program be passed as an arg to another?Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)List variables with prefix where the prefix is stored in another variablePassing paths with spaces as argumentsDoes bash provide support for using pointers?Expand variables in local bash script before passing it to SSHHow can I export a variable in bash where the variable name is comprised of two variables?Why does $$# return same result as $$ in the shell?
I need to indirectly reference a variable in the bash
shell.
I basically want to what you can do in make
by writing $($(var))
.
I have tried using $$var
which would be the most straight forward solution in bash
but then I get this error:
bash: $$var: bad substitution
Is there a way to do this?
What I am trying to do is to iterate over all the arguments ($1
, $2
, $3
, ...) to a program using an iteration variable and I cannot do this without indirection.
bash shell environment-variables variable arguments
add a comment |
I need to indirectly reference a variable in the bash
shell.
I basically want to what you can do in make
by writing $($(var))
.
I have tried using $$var
which would be the most straight forward solution in bash
but then I get this error:
bash: $$var: bad substitution
Is there a way to do this?
What I am trying to do is to iterate over all the arguments ($1
, $2
, $3
, ...) to a program using an iteration variable and I cannot do this without indirection.
bash shell environment-variables variable arguments
add a comment |
I need to indirectly reference a variable in the bash
shell.
I basically want to what you can do in make
by writing $($(var))
.
I have tried using $$var
which would be the most straight forward solution in bash
but then I get this error:
bash: $$var: bad substitution
Is there a way to do this?
What I am trying to do is to iterate over all the arguments ($1
, $2
, $3
, ...) to a program using an iteration variable and I cannot do this without indirection.
bash shell environment-variables variable arguments
I need to indirectly reference a variable in the bash
shell.
I basically want to what you can do in make
by writing $($(var))
.
I have tried using $$var
which would be the most straight forward solution in bash
but then I get this error:
bash: $$var: bad substitution
Is there a way to do this?
What I am trying to do is to iterate over all the arguments ($1
, $2
, $3
, ...) to a program using an iteration variable and I cannot do this without indirection.
bash shell environment-variables variable arguments
bash shell environment-variables variable arguments
asked Sep 15 '15 at 15:37
wefwefa3wefwefa3
5152722
5152722
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If you have var1=foo
and foo=bar
, you can get bar
by saying $!var1
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
Not that I can quickly find. The obvious guess of$!!var1
doesn't work. However, you can always do it manually, e.g.tmp=$!var1; echo $!tmp
.
– Tom Hunt
Sep 17 '15 at 15:05
add a comment |
Using /bin/bash
:
foo=bar
test=foo
echo $!test
# prints -> bar
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f229849%2findirectly-expand-variables-in-shell%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have var1=foo
and foo=bar
, you can get bar
by saying $!var1
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
Not that I can quickly find. The obvious guess of$!!var1
doesn't work. However, you can always do it manually, e.g.tmp=$!var1; echo $!tmp
.
– Tom Hunt
Sep 17 '15 at 15:05
add a comment |
If you have var1=foo
and foo=bar
, you can get bar
by saying $!var1
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
Not that I can quickly find. The obvious guess of$!!var1
doesn't work. However, you can always do it manually, e.g.tmp=$!var1; echo $!tmp
.
– Tom Hunt
Sep 17 '15 at 15:05
add a comment |
If you have var1=foo
and foo=bar
, you can get bar
by saying $!var1
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
If you have var1=foo
and foo=bar
, you can get bar
by saying $!var1
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
answered Sep 15 '15 at 15:43
Tom HuntTom Hunt
6,70521536
6,70521536
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
Not that I can quickly find. The obvious guess of$!!var1
doesn't work. However, you can always do it manually, e.g.tmp=$!var1; echo $!tmp
.
– Tom Hunt
Sep 17 '15 at 15:05
add a comment |
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
Not that I can quickly find. The obvious guess of$!!var1
doesn't work. However, you can always do it manually, e.g.tmp=$!var1; echo $!tmp
.
– Tom Hunt
Sep 17 '15 at 15:05
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
Is there a way to add multiple levels of indirection?
– wefwefa3
Sep 17 '15 at 12:44
1
1
Not that I can quickly find. The obvious guess of
$!!var1
doesn't work. However, you can always do it manually, e.g. tmp=$!var1; echo $!tmp
.– Tom Hunt
Sep 17 '15 at 15:05
Not that I can quickly find. The obvious guess of
$!!var1
doesn't work. However, you can always do it manually, e.g. tmp=$!var1; echo $!tmp
.– Tom Hunt
Sep 17 '15 at 15:05
add a comment |
Using /bin/bash
:
foo=bar
test=foo
echo $!test
# prints -> bar
add a comment |
Using /bin/bash
:
foo=bar
test=foo
echo $!test
# prints -> bar
add a comment |
Using /bin/bash
:
foo=bar
test=foo
echo $!test
# prints -> bar
Using /bin/bash
:
foo=bar
test=foo
echo $!test
# prints -> bar
answered Feb 14 '17 at 5:53
Nick GrealyNick Grealy
1266
1266
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f229849%2findirectly-expand-variables-in-shell%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