Linux ECHO output of a ECHO variable [duplicate]Indirectly access environment variableHow can I run growisofs via sudo?Need to set a variable with “[]”list files and store it in variablesAssign Subshell background process pid to variableHow to echo makefile variable through Make's $(shell …)Issues with storing an echo of a date conversion into a string variable inunixGet specific result from functionscript set command output to variableDifference between 'cat < file.txt' and 'echo < file.txt'Declaring a variable that does not have inputPutting external IP into a variable - grep operation failed
Is this apparent Class Action settlement a spam message?
Two monoidal structures and copowering
Roman Numeral Treatment of Suspensions
How do I find the solutions of the following equation?
How to Reset Passwords on Multiple Websites Easily?
How did Arya survive the stabbing?
How do I extract a value from a time formatted value in excel?
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
Gears on left are inverse to gears on right?
What happens if you roll doubles 3 times then land on "Go to jail?"
Is expanding the research of a group into machine learning as a PhD student risky?
when is out of tune ok?
What is the difference between "behavior" and "behaviour"?
Anatomically Correct Strange Women In Ponds Distributing Swords
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Increase performance creating Mandelbrot set in python
Is there a good way to store credentials outside of a password manager?
Sort a list by elements of another list
How easy is it to start Magic from scratch?
Is HostGator storing my password in plaintext?
Is exact Kanji stroke length important?
Return the Closest Prime Number
Why, precisely, is argon used in neutrino experiments?
What is the best translation for "slot" in the context of multiplayer video games?
Linux ECHO output of a ECHO variable [duplicate]
Indirectly access environment variableHow can I run growisofs via sudo?Need to set a variable with “[]”list files and store it in variablesAssign Subshell background process pid to variableHow to echo makefile variable through Make's $(shell …)Issues with storing an echo of a date conversion into a string variable inunixGet specific result from functionscript set command output to variableDifference between 'cat < file.txt' and 'echo < file.txt'Declaring a variable that does not have inputPutting external IP into a variable - grep operation failed
This question already has an answer here:
Indirectly access environment variable [duplicate]
3 answers
I have a variable (var
) which return value as VAR1
($var
has the value VAR1
).
There is an input file which has VAR1
defined (VAR1=ABCDEF
)
How can I use echo
to get the value ABCDEF
using $var
??
I tried echo $(echo $var)
and many other options, but I always get output as VAR1
or echo VAR1
but never ABCDEF
. I used source
in file with VAR1
declared, tried in command prompt etc.
variable echo
New contributor
marked as duplicate by Kusalananda♦, DopeGhoti, jimmij, nwildner, muru 2 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Indirectly access environment variable [duplicate]
3 answers
I have a variable (var
) which return value as VAR1
($var
has the value VAR1
).
There is an input file which has VAR1
defined (VAR1=ABCDEF
)
How can I use echo
to get the value ABCDEF
using $var
??
I tried echo $(echo $var)
and many other options, but I always get output as VAR1
or echo VAR1
but never ABCDEF
. I used source
in file with VAR1
declared, tried in command prompt etc.
variable echo
New contributor
marked as duplicate by Kusalananda♦, DopeGhoti, jimmij, nwildner, muru 2 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Indirectly access environment variable [duplicate]
3 answers
I have a variable (var
) which return value as VAR1
($var
has the value VAR1
).
There is an input file which has VAR1
defined (VAR1=ABCDEF
)
How can I use echo
to get the value ABCDEF
using $var
??
I tried echo $(echo $var)
and many other options, but I always get output as VAR1
or echo VAR1
but never ABCDEF
. I used source
in file with VAR1
declared, tried in command prompt etc.
variable echo
New contributor
This question already has an answer here:
Indirectly access environment variable [duplicate]
3 answers
I have a variable (var
) which return value as VAR1
($var
has the value VAR1
).
There is an input file which has VAR1
defined (VAR1=ABCDEF
)
How can I use echo
to get the value ABCDEF
using $var
??
I tried echo $(echo $var)
and many other options, but I always get output as VAR1
or echo VAR1
but never ABCDEF
. I used source
in file with VAR1
declared, tried in command prompt etc.
This question already has an answer here:
Indirectly access environment variable [duplicate]
3 answers
variable echo
variable echo
New contributor
New contributor
edited yesterday
Kusalananda♦
138k17258426
138k17258426
New contributor
asked yesterday
shashank barkishashank barki
41
41
New contributor
New contributor
marked as duplicate by Kusalananda♦, DopeGhoti, jimmij, nwildner, muru 2 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda♦, DopeGhoti, jimmij, nwildner, muru 2 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Assuming that you are using the bash
shell:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ echo "$!var"
ABCDEF
By using $!var
you use variable indirection in bash
. The value of the variable var
is used to get the name of the variable to expand.
In bash
you could also use a name reference variable:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ declare -n var="VAR1"
$ echo "$var"
ABCDEF
Here, the var
variable refers to the VAR1
variable, so $var
will expand to whatever $VAR1
expands to.
Name references are originally a ksh
feature, and in that shell they are declare with typeset -n
.
Name references are extremely useful fo passing references to arrays in calls to shell functions.
In any sh
shell:
$ . ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ eval "echo "$$var""
ABCDEF
The eval
utility takes a string which it will re-evaluate. Here, we give it the string echo "$VAR1"
(after expansion of $var
).
The issue with eval
is that it's easy to introduce errors or vulnerabilities with it, by carelessly creating its argument string.
add a comment |
Assuming you are using bash
, you can accomplish this easily with an indirect reference:
$ foo=bar
$ bar=magicword
$ printf "%sn" "$!foo"
magicword
The syntax $var
(or $var
) yields the contents of the variable var
.
The syntax $!var
yields the contents of the variable named in var
.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that you are using the bash
shell:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ echo "$!var"
ABCDEF
By using $!var
you use variable indirection in bash
. The value of the variable var
is used to get the name of the variable to expand.
In bash
you could also use a name reference variable:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ declare -n var="VAR1"
$ echo "$var"
ABCDEF
Here, the var
variable refers to the VAR1
variable, so $var
will expand to whatever $VAR1
expands to.
Name references are originally a ksh
feature, and in that shell they are declare with typeset -n
.
Name references are extremely useful fo passing references to arrays in calls to shell functions.
In any sh
shell:
$ . ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ eval "echo "$$var""
ABCDEF
The eval
utility takes a string which it will re-evaluate. Here, we give it the string echo "$VAR1"
(after expansion of $var
).
The issue with eval
is that it's easy to introduce errors or vulnerabilities with it, by carelessly creating its argument string.
add a comment |
Assuming that you are using the bash
shell:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ echo "$!var"
ABCDEF
By using $!var
you use variable indirection in bash
. The value of the variable var
is used to get the name of the variable to expand.
In bash
you could also use a name reference variable:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ declare -n var="VAR1"
$ echo "$var"
ABCDEF
Here, the var
variable refers to the VAR1
variable, so $var
will expand to whatever $VAR1
expands to.
Name references are originally a ksh
feature, and in that shell they are declare with typeset -n
.
Name references are extremely useful fo passing references to arrays in calls to shell functions.
In any sh
shell:
$ . ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ eval "echo "$$var""
ABCDEF
The eval
utility takes a string which it will re-evaluate. Here, we give it the string echo "$VAR1"
(after expansion of $var
).
The issue with eval
is that it's easy to introduce errors or vulnerabilities with it, by carelessly creating its argument string.
add a comment |
Assuming that you are using the bash
shell:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ echo "$!var"
ABCDEF
By using $!var
you use variable indirection in bash
. The value of the variable var
is used to get the name of the variable to expand.
In bash
you could also use a name reference variable:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ declare -n var="VAR1"
$ echo "$var"
ABCDEF
Here, the var
variable refers to the VAR1
variable, so $var
will expand to whatever $VAR1
expands to.
Name references are originally a ksh
feature, and in that shell they are declare with typeset -n
.
Name references are extremely useful fo passing references to arrays in calls to shell functions.
In any sh
shell:
$ . ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ eval "echo "$$var""
ABCDEF
The eval
utility takes a string which it will re-evaluate. Here, we give it the string echo "$VAR1"
(after expansion of $var
).
The issue with eval
is that it's easy to introduce errors or vulnerabilities with it, by carelessly creating its argument string.
Assuming that you are using the bash
shell:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ echo "$!var"
ABCDEF
By using $!var
you use variable indirection in bash
. The value of the variable var
is used to get the name of the variable to expand.
In bash
you could also use a name reference variable:
$ source ./file
$ echo "$VAR1"
ABCDEF
$ declare -n var="VAR1"
$ echo "$var"
ABCDEF
Here, the var
variable refers to the VAR1
variable, so $var
will expand to whatever $VAR1
expands to.
Name references are originally a ksh
feature, and in that shell they are declare with typeset -n
.
Name references are extremely useful fo passing references to arrays in calls to shell functions.
In any sh
shell:
$ . ./file
$ echo "$VAR1"
ABCDEF
$ var=VAR1
$ eval "echo "$$var""
ABCDEF
The eval
utility takes a string which it will re-evaluate. Here, we give it the string echo "$VAR1"
(after expansion of $var
).
The issue with eval
is that it's easy to introduce errors or vulnerabilities with it, by carelessly creating its argument string.
edited yesterday
answered yesterday
Kusalananda♦Kusalananda
138k17258426
138k17258426
add a comment |
add a comment |
Assuming you are using bash
, you can accomplish this easily with an indirect reference:
$ foo=bar
$ bar=magicword
$ printf "%sn" "$!foo"
magicword
The syntax $var
(or $var
) yields the contents of the variable var
.
The syntax $!var
yields the contents of the variable named in var
.
add a comment |
Assuming you are using bash
, you can accomplish this easily with an indirect reference:
$ foo=bar
$ bar=magicword
$ printf "%sn" "$!foo"
magicword
The syntax $var
(or $var
) yields the contents of the variable var
.
The syntax $!var
yields the contents of the variable named in var
.
add a comment |
Assuming you are using bash
, you can accomplish this easily with an indirect reference:
$ foo=bar
$ bar=magicword
$ printf "%sn" "$!foo"
magicword
The syntax $var
(or $var
) yields the contents of the variable var
.
The syntax $!var
yields the contents of the variable named in var
.
Assuming you are using bash
, you can accomplish this easily with an indirect reference:
$ foo=bar
$ bar=magicword
$ printf "%sn" "$!foo"
magicword
The syntax $var
(or $var
) yields the contents of the variable var
.
The syntax $!var
yields the contents of the variable named in var
.
edited yesterday
answered yesterday
DopeGhotiDopeGhoti
46.6k56190
46.6k56190
add a comment |
add a comment |
-echo, variable