Bash shell script (test.sh)

#!/bin/bash

echo "Executing a bash statement"
export bashvar=100

cat << EOF > pyscript.py
#!/usr/bin/python
import subprocess

print 'Hello python'
subprocess.call(["echo", "$bashvar"])

EOF

chmod 755 pyscript.py
python ./pyscript.py
rm ./pyscript.py

Result

$ ./test.sh
Executing a bash statement
Hello python
100
$

References

  1. https://unix.stackexchange.com/questions/184726/how-to-include-python-script-inside-a-bash-script


신고

티스토리 툴바