Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105520

Re: Obtain the variable in bash.

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Obtain the variable in bash.
Date 2016-03-23 19:08 +1100
Message-ID <mailman.33.1458720535.2244.python-list@python.org> (permalink)
References <nctfkg$kt7$1@aspen.stu.neva.ru>

Show all headers | View raw


Hongyi Zhao <hongyi.zhao@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@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Obtain the variable in bash. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-23 07:12 +0000
  Re: Obtain the variable in bash. Chris Angelico <rosuav@gmail.com> - 2016-03-23 18:19 +1100
    Re: Obtain the variable in bash. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-23 08:35 +0000
      Re: Obtain the variable in bash. Chris Angelico <rosuav@gmail.com> - 2016-03-23 19:45 +1100
  Re: Obtain the variable in bash. Ben Finney <ben+python@benfinney.id.au> - 2016-03-23 19:08 +1100

csiph-web