Bash shell script (test.sh)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/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

1
2
3
4
5
$ ./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