[英]How to insert a python program into a bash script?
我有一個小型 python 程序,它解析一個文本文件並將輸出寫入另一個文件。 目前,我正在編寫一個 bash 腳本來多次調用這個程序,它看起來像:
for i in $(seq 1 100); do
python /home/Documents/myProgram.py myTextFile$i
done
#!/bin/bash
python - 1 2 3 << 'EOF'
import sys
print 'Argument List:', str(sys.argv)
EOF
我認為你應該能夠提出:
python << END
[Python code here]
END
對於簡單的腳本,您還可以使用 -c 選項運行 python。 例如
python -c "x=1; print x; print 'great program eh'"
請原諒線程死靈術,但這里缺少一種可能對某人有用的技術。
#!/bin/bash
""":" # Hide bash from python
for i in $(seq 1 100); do
python3 $(readlink -f "$0") myTextFile$i
done
exit
"""
# Python script starts here
import sys
print('Argument List: ', str(sys.argv))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.