是否有可能对于bash命令previous命令的结果之前继续吗? [英] Is it possible for bash commands to continue before the result of the previous command?

查看:159
本文介绍了是否有可能对于bash命令previous命令的结果之前继续吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从一个bash脚本运行的命令,并始终庆典等待的previous命令来完成,还是只是启动命令然后继续下一个?

例如:如果你运行bash脚本以下两个命令是有可能的事情失败

  CP的/ tmp / A / TMP / B
CP的/ tmp / B / TMP / C


解决方案

是的,如果你没有别的然后在bash脚本命令序列。你可以告诉bash运行一束平行的命令,然后等待他们全部完成,但是做这样的事情:

 命令1&放大器;
命令2&安培;
指令代码和放大器;
等待

在每个前三行的末尾的&符号告诉Bash在后台运行该命令。第四个命令,,是告诉bash要等到所有的子进程已经退出。

请注意,如果你做的事情这样,你将无法得到孩子命令的退出状态(并设置 -e 将无法正常工作),所以你不能告诉他们是成功还是以通常的方式失败。

借助 bash的手动有更多的信息(搜索的一路下跌约三分之二)。

When running commands from a bash script, does bash always wait for the previous command to complete, or does it just start the command then go on to the next one?

ie: If you run the following two commands from a bash script is it possible for things to fail?

cp /tmp/a /tmp/b
cp /tmp/b /tmp/c

解决方案

Yes, if you do nothing else then commands in a bash script are serialized. You can tell bash to run a bunch of commands in parallel, and then wait for them all to finish, but doing something like this:

command1 &
command2 &
command3 &
wait

The ampersands at the end of each of the first three lines tells bash to run the command in the background. The fourth command, wait, tells bash to wait until all the child processes have exited.

Note that if you do things this way, you'll be unable to get the exit status of the child commands (and set -e won't work), so you won't be able to tell whether they succeeded or failed in the usual way.

The bash manual has more information (search for wait, about two-thirds of the way down).

这篇关于是否有可能对于bash命令previous命令的结果之前继续吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆