从主 shell 脚本运行多个子 shell 脚本文件

时间:2021-03-17 09:43:47

标签: linux bash shell

我有一个主要的 shell 脚本文件 m1.sh 和另外两个脚本文件 s1.shs2.sh

这里我从 s1.sh 运行 s2.shm1.sh。 但问题是 s2.sh 仅在 s1.sh 完全运行后才开始运行。

m1.sh 如下所示

$cat m1.sh
#!/bin/bash
./s1.sh 
./s2.sh

如何在 s2.sh 开始运行时运行 s1.sh(我不想等到 s1.sh 完成)

1 个答案:

答案 0 :(得分:0)

你可以把启动它们作为后台进程,比如

#!/bin/bash
./s1.sh &
./s2.sh &

wait       # wait for all background processes to complete

for logfile in ./s1.log ./s2.log
do
    ... process "${logfile}" as needed
done