linux - 如何等到 shell 脚本启动的所有内容结束?

标签 linux bash shell

我正在使用嵌套的 shell 脚本。

我的问题和问的有点相似herehere .但不完全一样。

我试图从这些中得到解决方案但没有成功。

在我的 OuterMostShellScript.sh 中,我执行如下操作:

some commands
./runThisScriptX.sh
other commands
end of script.

runThisScriptX.sh 包含使用 & 运算符在后台运行某些进程的循环。

我希望每个由 ./runThisScriptX.sh 命令启动的进程在控件移动到我在上面的代码中所说的 other commands 行之前完成。

如何实现?

编辑:我也这样做了:

some commands
./runThisScriptX.sh
wait
other commands
end of script.

但是没有用。

最佳答案

两件事:

  • 找到你的脚本
  • 使用等待

你的脚本不会像这样:

some commands
. ./runThisScriptX.sh          # Note the leading . followed by space
wait                           # This would wait for the sourced script to finish
other commands
end of script

关于linux - 如何等到 shell 脚本启动的所有内容结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23066630/

相关文章:

linux - 通过 ssh 在 linux 服务器上更改密码的脚本

linux - bash 脚本 : calculate sum size of files

Bash - 解压缩 : command not found

bash - 从 PL/SQL Developer 和 SQL*plus 调用时,存储过程没有相同的结果

Shell 脚本等待进程完成

c - 如何递归列出所有目录?

linux - ELF的基址

linux - 我不知道这个脚本有什么问题!!我在这里比较 x 和 y

bash - 如何在 Bash 中将变量设置为命令的输出?

linux - $0 在下面的 bash 脚本中代表什么?