Linux shell脚本以不同的参数迭代调用相同的Python程序

时间:2021-12-18 10:31:31

I have a Python program that requires different parameters each time. The parameters are URLs stored in a file called urls.txt. So for example if urls.txt contains:

我有一个Python程序,每次都需要不同的参数。参数是存储在名为urls.txt的文件中的URL。例如,如果urls.txt包含:

abc.com
xyz.com
def.com
mno.com

I'd want to execute:

我想要执行:

python myProgram.py -u 'abc.com' -f output.txt
python myProgram.py -u 'xyz.com' -f output.txt
python myProgram.py -u 'def.com' -f output.txt
python myProgram.py -u 'mno.com' -f output.txt

How is this done?

这是怎么做到的?

1 个解决方案

#1


1  

for url in `cat urls.txt`
do
    python myProgram.py -u "$url" -f output.txt
done

It can also be done with a while loop and read:

它也可以通过while循环完成并读取:

while read url
do
    python myProgram.py -u "$url" -f output.txt
done <urls.txt

#1


1  

for url in `cat urls.txt`
do
    python myProgram.py -u "$url" -f output.txt
done

It can also be done with a while loop and read:

它也可以通过while循环完成并读取:

while read url
do
    python myProgram.py -u "$url" -f output.txt
done <urls.txt