Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Obtain the variable in bash. Date: Wed, 23 Mar 2016 19:08:46 +1100 Lines: 36 Message-ID: References: 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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105520 Hongyi Zhao 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 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