bash 脚本执行顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4445846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash script order of execution
提问by javamonkey79
Do lines in a bash script execute sequentially? I can't see any reason why not, but I am really new to bash scripting and I have a couple commands that need to execute in order.
bash 脚本中的行是否按顺序执行?我看不出任何原因,但我对 bash 脚本非常陌生,我有几个命令需要按顺序执行。
For example:
例如:
#!/bin/sh
# will this get finished before the next command starts?
./someLongCommand1 arg1
./someLongCommand2 arg1
采纳答案by Jim Lewis
Yes... unless you go out of your way to run one of the commands in the background, one will finish before the next one starts.
是的...除非您特意在后台运行其中一个命令,否则一个命令将在下一个命令开始之前完成。
回答by michiel
Yes, they are executed sequentially. However, if you run a program in the background, the next command in your script is executed immediately after the backgrounded command is started.
是的,它们是顺序执行的。但是,如果您在后台运行程序,则脚本中的下一个命令会在后台命令启动后立即执行。
#!/bin/sh
# will this get finished before the next command starts?
./someLongCommand1 arg1 &
./someLongCommand2 arg1 &
would result in an near-instant completion of the script; however, the commands started in it will not have completed. (You start a command in the background by putting an ampersand (&) behind the name.
将导致脚本几乎立即完成;但是,其中启动的命令不会完成。(您可以通过在名称后面放置一个与号 (&) 在后台启动命令。

