bash script order of execution

前端 未结 2 733
挽巷
挽巷 2020-11-30 14:38

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 o

2条回答
  •  -上瘾入骨i
    2020-11-30 14:59

    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.

提交回复
热议问题