On Sep 11, 10:25 am, nntpman68 <[EMAIL PROTECTED]> wrote:
> >> doesn't exactly work for Python scripts, though:
>
> >> $ cat env.py
> >> #!/usr/bin/env python
> >> import os
> >> os.environ["TEST"] = "hello"
>
> >> $ . ./env.py && env | grep TEST
> >> import: unable to open X server `'.
> >> bash:
doesn't exactly work for Python scripts, though:
$ cat env.py
#!/usr/bin/env python
import os
os.environ["TEST"] = "hello"
$ . ./env.py && env | grep TEST
import: unable to open X server `'.
bash: os.environ[TEST]: command not found
There's two options for the desperate ones.
1. Assumin
>
> 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> . sete
John Lawrence wrote:
You can make a command use the current shell though if you use the '.'
command e.g.:
jl > cat env.sh
export TEST='hello'
jl > ./env.sh && env | grep TEST #Doesn't set TEST in parent shell
jl > . ./env.sh && env | grep TEST #Adding '. ' before the
comman
>
> when a process starts, it gets a *copy* of the parent's environment. it
> can modify that copy, but it cannot modify the variables in the parent.
You can make a command use the current shell though if you use the '.'
command e.g.:
jl > cat env.sh
export TEST='hello'
jl > ./env.sh && env |
aditya shukla wrote:
Can i add any environment variable to bash from my python script? so
that when i use env command then i can see that environment variable.
not if you run the script from the shell.
when a process starts, it gets a *copy* of the parent's environment. it
can modify that c
Hello folks
Can i add any environment variable to bash from my python script? so that
when i use env command then i can see that environment variable.
Thanks
Aditya
--
http://mail.python.org/mailman/listinfo/python-list