How to set environment variables for single process

In bash, you simply prefix a command with one or more XXX="YYY" pairs, e.g.

$ A="B" X="Y" python print_env.py
...
A=B
X=Y

The code for print_env.py:

import os

for ev in os.environ:
  print "{0}={1}".format(ev, os.environ[ev])

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.