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


Groups > comp.lang.python > #105520

Re: Obtain the variable in bash.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Obtain the variable in bash.
Date Wed, 23 Mar 2016 19:08:46 +1100
Lines 36
Message-ID <mailman.33.1458720535.2244.python-list@python.org> (permalink)
References <nctfkg$kt7$1@aspen.stu.neva.ru>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Xe6F3z6DuW7SxyjyIvp0dgA0thjU4Ei8XNPfNi8GyQJg==
Cancel-Lock sha1:AfgauG9snjSL4A7RJHZgCqRGOk8=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'variable,': 0.07; 'os;': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'variables': 0.15; 'exported': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:variable': 0.16; 'variable.': 0.16; 'wing': 0.16; 'shell': 0.18; 'variable': 0.18; 'discussion': 0.24; 'testing': 0.25; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'url:wikipedia': 0.29; 'environment': 0.29; 'print': 0.30; 'url:wiki': 0.30; '(i.e.,': 0.30; 'run': 0.33; 'follows:': 0.35; 'url:org': 0.36; 'child': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'environment.': 0.37; 'one,': 0.37; 'skip:o 20': 0.38; 'means': 0.39; 'url:en': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'export': 0.63; 'inherit': 0.66; 'social': 0.71; '_o__)': 0.84; 'affected.': 0.84; 'god,': 0.84; 'received:125': 0.84; '8bit%:18': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:105520

Show key headers only | 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