无需引入单独的shell和python脚本,单个文件可以兼而有之!
用以下顺序替换您的shebang行:
#!/bin/sh
# Shell commands follow
# Next line is bilingual: it starts a comment in Python, and is a no-op in shell
""":"
# Find a suitable python interpreter (adapt for your specific needs)
for cmd in python3.5 python3 /opt/myspecialpython/bin/python3.5.99 ; do
command -v > /dev/null $cmd && exec $cmd $0 "$@"
done
echo "OMG Python not found, exiting!!!!!11!!eleven" >2
exit 2
":"""
# PrevIoUs line is bilingual: it ends a comment in Python, and is a no-op in shell
# Shell commands end here
# Python script follows (example commands shown)
import sys
print ("running Python!")
print (sys.argv)