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













0
















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.










share|improve this question









New contributor




shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.






















    0
















    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.










    share|improve this question









    New contributor




    shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    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.




















      0












      0








      0









      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.










      share|improve this question









      New contributor




      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.













      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






      share|improve this question









      New contributor




      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday









      Kusalananda

      138k17258426




      138k17258426






      New contributor




      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      shashank barkishashank barki

      41




      41




      New contributor




      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      shashank barki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      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.






















          2 Answers
          2






          active

          oldest

          votes


















          6














          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.






          share|improve this answer
































            3














            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.






            share|improve this answer































              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6














              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.






              share|improve this answer





























                6














                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.






                share|improve this answer



























                  6












                  6








                  6







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  KusalanandaKusalananda

                  138k17258426




                  138k17258426























                      3














                      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.






                      share|improve this answer





























                        3














                        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.






                        share|improve this answer



























                          3












                          3








                          3







                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited yesterday

























                          answered yesterday









                          DopeGhotiDopeGhoti

                          46.6k56190




                          46.6k56190













                              -echo, variable

                              Popular posts from this blog

                              Frič See also Navigation menuinternal link

                              Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

                              fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox