Bash Execute Python
Simple Example
$ foo="hello world"; python -c "print('$foo')"
$ bar=`python -c "print('hello world')"`; echo $bar
$ foo="hello world"
$ python << EOF
> print('$foo')
> EOF
Send Parameters to python
$ python -c "import sys; print(sys.argv[1])" "hello world"
Execute Python Script
$ python test.py "hello world"
# test.py
import sys
print(sys.argv[1])
Reference
- 如何在 bash 里面写 python, 2018-06-06, 漠漠颜
- shell调用python脚本,并且向python脚本传递参数, 2022-10-17, Hwrn.aou