January 28, 2022

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

The code for print_env.py:

import os

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

Leave a Reply

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