我有带有以下代码的Invoke_test.sh:
echo "invoke script started"
sh test1.sh >output1.log &
sh test2.sh > output2.log
echo "test 1 completed " >> output1.log
echo "test 2 completed " >> output2.log
Test1.sh:
echo "running test1.sh"
sleep 5
echo "test1.sh completed"
Test2.sh:
echo "running test2.sh"
sleep 10
echo "test2.sh completed"
因此,当我通过sh Invoke_test.sh执行Invoke_test.sh时
在输出日志文件中,我可以找到例如output1.log
运行test1.sh的操作已完成
但无法从Invoke_Test.sh脚本测试1中获取我尝试定向到日志的以下行
这里的要求是并行运行两个外壳脚本,一旦这两个脚本执行完成,我想执行这两行回显“test1已完成”>>output1.log回应“test2已完成”>>output2.log
我是Unix的新手,所以我会理解为什么这种行为会以一种简单的方式发生,以及我如何才能获得所需的输出
1条答案
按热度按时间chhqkbe11#
如果您的目标是在所有后台进程完成之前执行
wait
,请使用wait
: