如何在bash脚本中插入python程序? [英] How to insert a python program into a bash script?

查看:164
本文介绍了如何在bash脚本中插入python程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的python程序,该程序分析一个文本文件并将输出写入另一个文件.目前,我正在编写一个bash脚本来多次调用该程序,看起来像:

I have a small python program that parses a text file and writes the output to another file. Currently, I am writing a bash script to call this program several times, it looks something like:

for i in $(seq 1 100); do

          python /home/Documents/myProgram.py myTextFile$i

done

这很好,但是我想知道bash脚本文件中是否可以包含python程序,因此当另一个用户运行该脚本时,他们不需要在内存中包含python程序;也就是说,是否可以将python程序复制并粘贴到bash脚本中,然后在脚本本身中运行它?

This works fine but I want to know if it is possible to have the python program inside the bash script file so when another user runs the script they don't need to have the python program in their memory; i.e., is it possible to copy and paste the python program into the bash script and run it from within the script itself?

推荐答案

#!/bin/bash

python - 1 2 3 << 'EOF'
import sys

print 'Argument List:', str(sys.argv)
EOF

输出:

Argument List: ['-', '1', '2', '3']

这篇关于如何在bash脚本中插入python程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆