file1 & echo "yoyoyo 2" > file2 & rm -f file1 f-6ren">
gpt4 book ai didi

linux - 一次运行所有基本命令,然后在它们全部完成后按顺序运行

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:38 28 4
gpt4 key购买 nike

我将如何运行如下几个命令,以便在所有后台命令完成后执行(清理)最后一行?

echo "oyoy 1" > file1 &
echo "yoyoyo 2" > file2 &
rm -f file1 file2

当然, echo 命令对我来说是不同的,需要很长时间才能完成(我可以手动删除文件或使用我知道的另一个脚本,但我想知道如何在一个脚本中完成此操作..)

谢谢!

最佳答案

来自 the docs

 wait [n ...]
Wait for each specified process and return its termination sta-
tus. Each n may be a process ID or a job specification; if a
job spec is given, all processes in that job's pipeline are
waited for. If n is not given, all currently active child pro-
cesses are waited for, and the return status is zero. If n
specifies a non-existent process or job, the return status is
127. Otherwise, the return status is the exit status of the
last process or job waited for.

所以你可以像这样等待后台进程完成:

echo "oyoy 1" > file1 &
echo "yoyoyo 2" > file2 &
wait
rm -f file1 file2

关于linux - 一次运行所有基本命令,然后在它们全部完成后按顺序运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15168051/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com