Obtain the variable in bash.

Ben Finney ben+python at benfinney.id.au
Wed Mar 23 04:08:46 EDT 2016


Hongyi Zhao <hongyi.zhao at gmail.com> writes:

> I exported a variable in my .bashrc as follows:
>
> export MY_VAR="fdsfads"

That ‘export’ means that child processes of this one (i.e., the shell in
which that command executed) will inherit that variable in their
environment.

Processes that are not children of this one, will not be affected.

> Then I soured the .bashrc and do the testing as follows:
>
> werner at debian-01:~$ python -c "import os; print os.environ['MY_VAR']"
> fdsfads

Yes. Because that ‘python’ process is started from a process which has
that exported variable, that ‘python’ process inherits the variable in
its environment.

> But, when I run the same commands in pycharm and wing ide, I failed the 
> obtain the value of this variable.

Were they started as child processes from the shell that is exporting
the variable?

See <URL:https://en.wikipedia.org/wiki/Environment_variable#Unix_2> for
a discussion of how the process environment variables are inherited.

-- 
 \      “Every man would like to be God, if it were possible; some few |
  `\          find it difficult to admit the impossibility.” —Bertrand |
_o__)                    Russell, _Power: A New Social Analysis_, 1938 |
Ben Finney




More information about the Python-list mailing list