Reputation: 31674
Currently, I have following code works:
a.sh
echo "start"
export abc="hello"
a=`python a.py`
echo $a
echo "end"
a.py
import os
print os.getenv('abc')*2
Above, my shell script need one python script' help to handle something then back the answer to shell script.
Although it works, we need to write another python file, the requirement is to afford single file to users, so how it makes, I remember I have once saw some kind of realize which combine shell and python code, could anyone also know that & give me some clue?
Upvotes: 1
Views: 1883
Reputation: 31674
a.sh
echo "start"
export abc="hello"
a=`python <<- EOF
import os
print os.getenv('abc')*2
EOF`
echo $a
echo "end"
Upvotes: 2
Reputation: 10138
You could use python
's -c
option in your a.sh file:
echo "start"
export abc="hello"
a=$(python -c "import os ; print os.getenv('abc') * 2")
echo $a
echo "end"
Upvotes: 5