文本文件中的每一行在bash指挥 [英] text file each line to command in bash

查看:166
本文介绍了文本文件中的每一行在bash指挥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有一个pythonscript这需要像这样的参数

okay so I have a pythonscript that takes an argument like so

& ./myscript.py argumentishere

移动你想要做的是阅读有文字多发性行和每行执行,像这样我的命令的文本文件

what u want to do is read a text file that has multipule lines of text and for each line execute my command like so

& ./myscript.py line1
& ./myscript.py line2
& ./myscript.py line3
ect.ect.ect

我怎么能在bash脚本实现这一点。

how can I achieve this in a bash script

推荐答案

虽然你可以使用bash脚本实现这一点,可能是更容易的方法是使用的xargs 工具

While you can achieve this with a bash script, probably the easier way is to use the xargs utility.

xargs -L 1 ./myscript.py <inputfile

bash的方法是:

The bash way would be:

while read line
do
    ./myscript $line
done <inputfile

这篇关于文本文件中的每一行在bash指挥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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