Adding environment variables to bash.

John Lawrence mail at johnlawrence.net
Thu Sep 11 06:51:53 EDT 2008


>
> doesn't exactly work for Python scripts, though:
>

True, but you can use it in the following (admittedly messy) way:

jl> cat setenv.sh
/usr/bin/env python $@
. ./settmp
rm settmp

jl> cat env.py
#!/usr/bin/python
command = "export TEST='hello'\n"
open('settmp', 'w').write(command)

jl> . setenv.sh env.py && env | grep TEST
TEST=hello

Note this won't set the environment variable until the end of the script, so
if it's used in the script as well then it'll also need to be set with, for
example, os.environ["TEST"] = "hello"

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080911/b363be28/attachment-0001.html>


More information about the Python-list mailing list