write and execute python + shell script



Write n execute shell n python script in same file same time !!!!


Yes you can combine shell and python script in same file and also execute them.
All you need to do is open file write shebang line pointing to shell interpreter then write your shell script at last put this line exec python "$0" "$@" , When shell reaches the line exec python "$0" "$@", it causes the shell process to end and Python interpreter to be executed rest of the python code.


The lines between """:" and " """ are seen as a Python multi line string and ignored by python interpreter. And also it ignores shebang line #!/bin/sh looks like comment.



1 #!/bin/sh
2
3 """:"
4 echo "This is shell script.”
5 exec python "$0" "$@"
6 """
7
8 import sys, platform
9 print "You can write python script here !!!"
10 print "Python version: " + sys.version
11 print "Platform: " + platform.system() + platform.release()
12 sys.exit (0)