如何在bash脚本中插入python程序?

编程入门 行业动态 更新时间:2024-10-27 00:34:32
本文介绍了如何在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程序?

本文发布于:2023-10-09 10:27:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   程序   如何在   bash   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!