Environment variables set from python not visible in shell script

  bash, linux, python, python-2.7, shell

I have a python script which sets environment variables. I am running this python script from a shell script and the expectation is to read the value of environment variables set by the python script.

#Python script – x.py#

import os
os.environ['FRUIT'] = 'APPLE'

#Shell script – x.sh#

python -c "import x"
echo $FRUIT

But that does not seem to be working. Nothing gets printed by the shell script. Can any one please explain why it is so and how to fix this?

Source: Python Questions

LEAVE A COMMENT