I wanted to set some environment variables in my bash / linux terminal using python script.
I tried:
import os;
os.environ['HOME_ROOT'] = '/home/aloha'
os.putenv("HOME_ROOT", "/home/aloha")
but it wasn't setting the variables.
If I do as shown below from the shell script, it sets the required variables:
setenv HOME_ROOT /home/aloha
But I wanted to do the same using Python script. Am I making any mistake, or is it not possible to set env variables in bash/linux terminals from Python?
Please share your comments!
sourceit so it runs in the same context, not as a child. And you generaly use theexportcommand so that the env vars will be inherited by child processes.putenv, you are not actually setting those variablesssh-agentwork -- writing a snippet of shell script to stdout, such that a parent process can read andevalit -- may be informative. Note that usingevalrisks security vulnerabilities unless you trust the program doing that generation to usepipes.quote()or similar tools to escape values not to be parsed as code.