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

                              Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

                              Nikolai Prilezhaev Bibliography References External links Navigation menuEarly Russian Organic Chemists and Their Legacy092774english translationRussian Biography

                              How to link a C library to an Assembly library on Mac with clangHow do you set, clear, and toggle a single bit?Find (and kill) process locking port 3000 on MacWho is listening on a given TCP port on Mac OS X?How to start PostgreSQL server on Mac OS X?Compile assembler in nasm on mac osHow do I install pip on macOS or OS X?AFNetworking 2.0 “_NSURLSessionTransferSizeUnknown” linking error on Mac OS X 10.8C++ code for testing the Collatz conjecture faster than hand-written assembly - why?How to link a NASM code and GCC in Mac OS X?How to run x86 .asm on macOS Sierra