Reputation: 807
I am testing a simple python script to set an environmental variable by os module but it seems it doesn't work, what is wrong with my code or logic?
webcluster4u@ingestion-jenkins-vm:~$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['ENV']='ss'
>>> os.environ.get('ENV')
'ss'
>>> exit()
webcluster4u@ingestion-jenkins-vm:~$ echo $ENV
webcluster4u@ingestion-jenkins-vm:~$
Upvotes: 1
Views: 203
Reputation: 3347
There's nothing wrong with your script.
This by design. Your python script runs in a child process which inherits the shell's environment, but does not affect it. Any changes you make to the environment will affect the script's process and it's children if any.
Upvotes: 4