Is it possible for bash commands to continue before the result of the previous command?

后端 未结 6 1387
心在旅途
心在旅途 2020-11-27 16:39

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?

i

6条回答
  •  情深已故
    2020-11-27 16:52

    Unless you explicitly tell bash to start a process in the background, it will wait until the process exits. So if you write this:

    foo args &
    

    bash will continue without waiting for foo to exit. But if you don't explicitly put the process in the background, bash will wait for it to exit.

    Technically, a process can effectively put itself in the background by forking a child and then exiting. But since that technique is used primarily by long-lived processes, this shouldn't affect you.

提交回复
热议问题