How to pass shell variable to shell script from python

Rockins Chen ybc2084 at gmail.com
Wed Feb 27 02:37:25 EST 2008


Clearly, I made some typing mistake, it's the shbang line! it should be:
#!/usr/bin/python

then, just set os.environ is okay:
os.environ["target"] = "localhost.localdomain.org"

according python's documentation, setting os.environ will implicitly call
os.putenv().

2008/2/27, Rockins Chen <ybc2084 at gmail.com>:
>
> Hi all,
>
> I encountered a problem: I have a python script, let's just name it
> caller.py, It calls a shell script, which is named callee.sh. In callee.sh,
> it need a shell variable $target, which should be supplied by caller.py(cannot
> pass by argument). I try to use os.environ to do this, as follows:
>
> caller.py
> ------------------
> #/usr/bin/python
>
> import os
>
> os.environ["target"] = "localhost.localdomain.org"
> os.putenv("target", "localhost.localdomain.org")
> os.system("./callee.sh")
> -------------------
>
> callee.sh
> -------------------
> #!/bin/bash
>
> echo $target
> exit 0
> --------------------
>
> But, unluckily, it didn't work. What can I do?
>
> TIA,
>
>
> --
> BRs,
> Rockins Chen
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> UESTC, Chengdu, Sichuan, China
> http://www.dormforce.net/blog/rockins
> http://rockins.cublog.cn
> ybc2084 at gmail.com




-- 
BRs,
Rockins Chen

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UESTC, Chengdu, Sichuan, China
http://www.dormforce.net/blog/rockins
http://rockins.cublog.cn
ybc2084 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080227/76d104d6/attachment-0001.html>


More information about the Python-list mailing list