bash script order of execution

前端 未结 2 721
挽巷
挽巷 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条回答
  • 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.

    0 讨论(0)
  • 2020-11-30 15:09

    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.

    0 讨论(0)
提交回复
热议问题