Shell脚本循环 [英] Shell script looping

查看:112
本文介绍了Shell脚本循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家大师



我需要你的帮助。我有一个命令,我在终端colsole中运行。

我想让它一个接一个地运行文件夹中的所有文件,并将输出保存为txt文件。目前,我只能手动为一个文件逐个运行它,并在colsole中获取输出。



原始命令是

Dear Expert guru

I need your help. I have a command which I am running in terminal colsole.
I want to make it run for all the files in the folder one by one and save the output as txt file. At the moment, I can only run it one by one manually for single file and get the output in colsole.

Original command is

python main.py -m test -class input.csv 





我在shell脚本循环中尝试像这样循环




and
I am trying looping like this in shell script loop

for file in  *.csv; 
do
    python main.py -m test -class  <"$file" &
done





你能帮我做一个合适的循环吗?



问候



我的尝试:



我正在尝试为所有可用文件的循环命令创建一个shell脚本.sh文件,这些文件逐个运行并保存输出,这是文本在控制台中。

但是我每次只能在colsole终端中手动运行这个命令。



can you help me in making a proper loop?

Greetings

What I have tried:

I am trying to make a shell script .sh file for the looping command for all available files which get run one by one and save the output which is text in console.
Yet I am only able to run this command in colsole terminal manually each time.

推荐答案

file&
done
file" & done





你可以帮我做一个合适的循环吗?



问候



我尝试了什么:



我想做一个用于循环命令的shell脚本.sh文件,用于逐个运行的所有可用文件,并将输出保存为控制台中的文本。

但我只能在colsole终端中手动运行此命令每次。



can you help me in making a proper loop?

Greetings

What I have tried:

I am trying to make a shell script .sh file for the looping command for all available files which get run one by one and save the output which is text in console.
Yet I am only able to run this command in colsole terminal manually each time.


删除& 。在那里,每个python命令作为单独的后台进程启动,所以他们将所有这些都是以可怕的混乱运行。如果没有& ,它们将按预期顺序运行。
Delete the &. With it there, each python command is launched as a separate background process, so they will all run in a terrible jumble. Without the &, they will run sequentially as you expect.


这篇关于Shell脚本循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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