Will the inherited environment variables be inherited as environment variables or as shell variables?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Say my bash shell have the following environment variable:



export a="Hello World"


If I executed a process from the bash shell, the a environment variable will be inherited by this child process.



My question is: will a be inherited by the child process as an environment variable or as a shell variable, that is, will a in the child process be exported?










share|improve this question

























    up vote
    1
    down vote

    favorite












    Say my bash shell have the following environment variable:



    export a="Hello World"


    If I executed a process from the bash shell, the a environment variable will be inherited by this child process.



    My question is: will a be inherited by the child process as an environment variable or as a shell variable, that is, will a in the child process be exported?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Say my bash shell have the following environment variable:



      export a="Hello World"


      If I executed a process from the bash shell, the a environment variable will be inherited by this child process.



      My question is: will a be inherited by the child process as an environment variable or as a shell variable, that is, will a in the child process be exported?










      share|improve this question













      Say my bash shell have the following environment variable:



      export a="Hello World"


      If I executed a process from the bash shell, the a environment variable will be inherited by this child process.



      My question is: will a be inherited by the child process as an environment variable or as a shell variable, that is, will a in the child process be exported?







      linux environment-variables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 24 '17 at 19:53









      user7681202

      237414




      237414




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          As an environment variable.



          This means that any child process that the child process starts will inherit the variable as well.



          Testing:



          $ export FOO=bar
          $ sh
          $ sh
          $ sh
          $ echo "$FOO"
          bar
          $ exit
          $ exit
          $ exit


          Above, the shell creating the environment variable FOO started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO has the value bar.



          Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):



          $ export FOO=bar
          $ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
          bar
          quux
          $ echo "$FOO"
          bar


          (in this example, it doesn't matter that FOO is exported as ( ... ) subshells also inherit shell variables, but the the effect would have been the same had each ( ... ) been a totally separate process)



          Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).






          share|improve this answer





























            up vote
            0
            down vote













            You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".






            share|improve this answer




















              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394189%2fwill-the-inherited-environment-variables-be-inherited-as-environment-variables-o%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              As an environment variable.



              This means that any child process that the child process starts will inherit the variable as well.



              Testing:



              $ export FOO=bar
              $ sh
              $ sh
              $ sh
              $ echo "$FOO"
              bar
              $ exit
              $ exit
              $ exit


              Above, the shell creating the environment variable FOO started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO has the value bar.



              Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):



              $ export FOO=bar
              $ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
              bar
              quux
              $ echo "$FOO"
              bar


              (in this example, it doesn't matter that FOO is exported as ( ... ) subshells also inherit shell variables, but the the effect would have been the same had each ( ... ) been a totally separate process)



              Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).






              share|improve this answer


























                up vote
                3
                down vote



                accepted










                As an environment variable.



                This means that any child process that the child process starts will inherit the variable as well.



                Testing:



                $ export FOO=bar
                $ sh
                $ sh
                $ sh
                $ echo "$FOO"
                bar
                $ exit
                $ exit
                $ exit


                Above, the shell creating the environment variable FOO started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO has the value bar.



                Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):



                $ export FOO=bar
                $ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
                bar
                quux
                $ echo "$FOO"
                bar


                (in this example, it doesn't matter that FOO is exported as ( ... ) subshells also inherit shell variables, but the the effect would have been the same had each ( ... ) been a totally separate process)



                Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).






                share|improve this answer
























                  up vote
                  3
                  down vote



                  accepted







                  up vote
                  3
                  down vote



                  accepted






                  As an environment variable.



                  This means that any child process that the child process starts will inherit the variable as well.



                  Testing:



                  $ export FOO=bar
                  $ sh
                  $ sh
                  $ sh
                  $ echo "$FOO"
                  bar
                  $ exit
                  $ exit
                  $ exit


                  Above, the shell creating the environment variable FOO started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO has the value bar.



                  Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):



                  $ export FOO=bar
                  $ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
                  bar
                  quux
                  $ echo "$FOO"
                  bar


                  (in this example, it doesn't matter that FOO is exported as ( ... ) subshells also inherit shell variables, but the the effect would have been the same had each ( ... ) been a totally separate process)



                  Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).






                  share|improve this answer














                  As an environment variable.



                  This means that any child process that the child process starts will inherit the variable as well.



                  Testing:



                  $ export FOO=bar
                  $ sh
                  $ sh
                  $ sh
                  $ echo "$FOO"
                  bar
                  $ exit
                  $ exit
                  $ exit


                  Above, the shell creating the environment variable FOO started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO has the value bar.



                  Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):



                  $ export FOO=bar
                  $ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
                  bar
                  quux
                  $ echo "$FOO"
                  bar


                  (in this example, it doesn't matter that FOO is exported as ( ... ) subshells also inherit shell variables, but the the effect would have been the same had each ( ... ) been a totally separate process)



                  Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 24 '17 at 20:30

























                  answered Sep 24 '17 at 20:04









                  Kusalananda

                  106k14209327




                  106k14209327






















                      up vote
                      0
                      down vote













                      You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".






                          share|improve this answer












                          You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 24 '17 at 20:09









                          Jaroslav Kucera

                          4,3904621




                          4,3904621



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394189%2fwill-the-inherited-environment-variables-be-inherited-as-environment-variables-o%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay