How to pass shell variable to shell script from python

Gerardo Herzig gherzig at fmed.uba.ar
Wed Feb 27 06:17:21 EST 2008


Rockins Chen wrote:

>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,
>
>
>  
>
Well, if you have to use os.system, that could be
os.system("export target=localhost.localdomain.org; ./callee.sh")

Gerardo



More information about the Python-list mailing list