bash脚本中的行是否按顺序执行?我认为没有任何原因不按顺序执行,但我对bash脚本编写非常新手,我有几个命令需要按顺序执行。
例如:
#!/bin/sh
# will this get finished before the next command starts?
./someLongCommand1 arg1
./someLongCommand2 arg1
是的,它们按顺序执行。但是,如果您在后台运行程序,则脚本中的下一个命令将在后台命令启动后立即执行。
#!/bin/sh
# will this get finished before the next command starts?
./someLongCommand1 arg1 &
./someLongCommand2 arg1 &
使用该命令会导致脚本几乎立即完成;但是,在其中启动的命令将不会完成。 (通过在名称后面添加“&”符号来将命令启动到后台。)
是的...除非你特意将其中一个命令放在后台运行,否则每个命令都会在下一个命令开始之前完成。