bash 在bash中一个接一个地运行多个脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38152509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run multiple scripts one after another in bash
提问by El David
I'm trying to run three scripts one after the other. One requires a user to input a file. The scripts all run individually, and when I combine some with &&they work, but when I try to combine all three, it fails. They need each other to work, so it should go script1.sh -> script2.sh -> script3.pl.
我正在尝试一个接一个地运行三个脚本。一种要求用户输入文件。脚本全部单独运行,当我将一些与&&结合使用时,它们可以工作,但是当我尝试将所有三个结合时,它失败了。他们需要彼此工作,所以它应该是script1.sh -> script2.sh -> script3.pl。
- script1.shneeds 2 files inputted
- script2.shneeds to output a .csv
- script3.plruns on the .csvcreated and needs an input that I want to prompt the user for.
- script1.sh需要输入 2 个文件
- script2.sh需要输出一个.csv
- script3.pl在创建的.csv上运行,需要一个我想提示用户输入的输入。
Each takes a long time to run, so I'm also trying to have them run in the background with nohup
. They run individually as follows:
每个都需要很长时间才能运行,所以我也试图让它们在后台运行nohup
。它们分别运行如下:
script1.sh file1 file2
script2.sh > file.csv
script3.pl --input answer
I have tried using the following;
我尝试使用以下方法;
echo -n "Question? "
read answer
nohup script1.sh && script2.sh > file.csv && script3.pl --input $answer &
It will work with the question, script2.sh, and script3.pl, but when I had script1.shit wont work. Script1.shand script2.shcombined will also work, but I am trying to combine all of three.
它将处理问题script2.sh和script3.pl,但是当我有script1.sh 时它不起作用。Script1.sh和script2.sh结合使用也可以,但我正在尝试将所有三个结合起来。
采纳答案by agc
Try this:
尝试这个:
read -p "Question? " answer ; \
nohup script1.sh file1 file2 && \
nohup script2.sh > file.csv && \
nohup script3.pl --input $answer &
回答by Mark Setchell
I think you need a combined script like this - save as combined
:
我认为你需要一个这样的组合脚本 - 另存为combined
:
#!/bin/bash
script1.sh file1 file2
script2.sh > file.csv
script3.pl --input ""
Then you can run:
然后你可以运行:
nohup ./combined "answer" &