Linux 如何从另一个 sh 文件运行 sh 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9305714/
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
How to run sh file from another sh file
提问by Selvakumar Ponnusamy
I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job.
我有一个用于监视我的应用程序的 shell 脚本文件,该脚本将通过设置 cron 作业每 10 分钟执行一次。
I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to include my scripts to master file. How to run those sh file from master sh file
我想要一些与监控相关的脚本文件应该与主文件一起执行。所以我想将我的脚本包含到主文件中。如何从主 sh 文件运行那些 sh 文件
采纳答案by Behnam Safari
Take a look at this. If you want to run a script you can use:
看看这个。如果要运行脚本,可以使用:
./yourscript.sh
If your script has a loop, use:
如果您的脚本有循环,请使用:
./yourscript.sh&
If you want to get the console after starting scripts and you don't want to see it's output use:
如果您想在启动脚本后获取控制台并且不想看到它的输出,请使用:
./yourscript.sh > /dev/null 2>&1 &
So, in the master file you'll have:
因此,在主文件中,您将拥有:
./yourscript1.sh > /dev/null 2>&1 &
./yourscript2.sh > /dev/null 2>&1 &
./yourscript3.sh > /dev/null 2>&1 &
They will start together.
他们将一起开始。
回答by Kundan
Create file1.sh
创建文件1.sh
#! /bin/sh
echo "Hello World"
Create file2.sh
创建file2.sh
#! /bin/sh
details = `./file1.sh`
echo $details
give execute permission
给予执行权限
chmod +x file1.sh
chmod +x file2.sh
Now run your file
现在运行你的文件
./file2.sh
Output
输出
Hello World