On Mon, May 16, 2016 at 11:25 AM, Charles Mills <[email protected]> wrote:

> I'm not even real familiar with UNIX export and I expected it to work the
> other way. You set a value and then you send (export) it somewhere, no?
>
> Charles
>
>
​Actually, at least in BASH on Linux, you can either export then set or set
then export. They have the same effect. What export does​

​make a shell environment variable "available" to ​a sub-shell or a
program. Example transcript which may help a bit:

$ printenv X # no value yet
$ sh -c 'printenv X' # likewise in subshell
$ X='a' # set value
$ printenv X # show it's here
a
$ sh -c 'printenv X' # but not here
$ export X
[tsh009@it-johnmckown-linux ~]$ sh -c 'printenv X' # export makes it
available
a
[tsh009@it-johnmckown-linux ~]$ printenv Y # try again - not there
[tsh009@it-johnmckown-linux ~]$ sh -c 'printenv Y' # not here either
[tsh009@it-johnmckown-linux ~]$ export Y # export it
[tsh009@it-johnmckown-linux ~]$ printenv Y # still no value
[tsh009@it-johnmckown-linux ~]$ sh -c 'printenv Y' # likewise
[tsh009@it-johnmckown-linux ~]$ Y="bye bye" #set value
[tsh009@it-johnmckown-linux ~]$ printenv Y # ow, wow - it's here!
bye bye
[tsh009@it-johnmckown-linux ~]$ sh -c 'printenv Y' # likewise, wow.
bye bye
[tsh009@it-johnmckown-linux ~]$

​Actually the export does not "make an environment variable available".
What happens in UNIX is that the shell create a _new_ environment array (an
array of pointers to pointers to chars - char **envp) based upon what has
been exported. I.e. the only name/values exported are copies into a _NEW_
environment block which is sent to the command. That's why a shell script
or program cannot affect the environment of its parent.




-- 
The unfacts, did we have them, are too imprecisely few to warrant our
certitude.

Maranatha! <><
John McKown

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to