Passing bash variables to a script?

Viewed 20831

What's the best way to pass bash variables to a python script. I'd like to do something like the following:

$cat test.sh
#!/bin/bash

foo="hi"
python -c 'import test; test.printfoo($foo)'

$cat test.py
#!/bin/python

def printfoo(str):
    print str

When I try running the bash script, I get a syntax error:

  File "<string>", line 1
    import test; test.printfoo($foo)
                               ^
SyntaxError: invalid syntax
4 Answers
Related