run bunch of commands and wait

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4







share|improve this question
















  • 4




    Look into using the wait command.
    – Raman Sailopal
    Jan 22 at 8:57














up vote
0
down vote

favorite












I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4







share|improve this question
















  • 4




    Look into using the wait command.
    – Raman Sailopal
    Jan 22 at 8:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4







share|improve this question












I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4









share|improve this question











share|improve this question




share|improve this question










asked Jan 22 at 8:52









Ebrahim Poursadeqi

1135




1135







  • 4




    Look into using the wait command.
    – Raman Sailopal
    Jan 22 at 8:57












  • 4




    Look into using the wait command.
    – Raman Sailopal
    Jan 22 at 8:57







4




4




Look into using the wait command.
– Raman Sailopal
Jan 22 at 8:57




Look into using the wait command.
– Raman Sailopal
Jan 22 at 8:57










3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










command1 &
command2 &

wait
echo 'command1 and command2 have finished'

command3 &
command4 &

wait
echo 'command3 and command4 have finished'


The call to wait will pause the script until all backgrounded tasks have finished executing.



Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):



( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'


In the above case, command1 and command2 will run in the background, but not concurrently with each other.




Doing



command1 & command2
wait


is equivalent to



command1 &
command2
wait


... which will work, but command2 will not be running in the background and wait will not be called until command2 has finished executing.






share|improve this answer



























    up vote
    1
    down vote













    The actual answer of my question was something like this, special thanks from @raman-sailopal



    command1 & command2
    wait
    echo "command 1 and 2 has finished"
    command3 & command4





    share|improve this answer




















    • That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
      – Kusalananda
      Jan 22 at 9:55

















    up vote
    0
    down vote













    command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"


    & runs commands simultaneously



    ; emulates a new line - i.e. will be run after completion



    && runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)






    share|improve this answer




















    • This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
      – Stephen Kitt
      Jan 22 at 9:45










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418796%2frun-bunch-of-commands-and-wait%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    command1 &
    command2 &

    wait
    echo 'command1 and command2 have finished'

    command3 &
    command4 &

    wait
    echo 'command3 and command4 have finished'


    The call to wait will pause the script until all backgrounded tasks have finished executing.



    Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):



    ( command1; command2 ) &
    echo 'command1 and command2 are running'
    wait
    echo 'command1 and command2 have finished'


    In the above case, command1 and command2 will run in the background, but not concurrently with each other.




    Doing



    command1 & command2
    wait


    is equivalent to



    command1 &
    command2
    wait


    ... which will work, but command2 will not be running in the background and wait will not be called until command2 has finished executing.






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      command1 &
      command2 &

      wait
      echo 'command1 and command2 have finished'

      command3 &
      command4 &

      wait
      echo 'command3 and command4 have finished'


      The call to wait will pause the script until all backgrounded tasks have finished executing.



      Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):



      ( command1; command2 ) &
      echo 'command1 and command2 are running'
      wait
      echo 'command1 and command2 have finished'


      In the above case, command1 and command2 will run in the background, but not concurrently with each other.




      Doing



      command1 & command2
      wait


      is equivalent to



      command1 &
      command2
      wait


      ... which will work, but command2 will not be running in the background and wait will not be called until command2 has finished executing.






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        command1 &
        command2 &

        wait
        echo 'command1 and command2 have finished'

        command3 &
        command4 &

        wait
        echo 'command3 and command4 have finished'


        The call to wait will pause the script until all backgrounded tasks have finished executing.



        Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):



        ( command1; command2 ) &
        echo 'command1 and command2 are running'
        wait
        echo 'command1 and command2 have finished'


        In the above case, command1 and command2 will run in the background, but not concurrently with each other.




        Doing



        command1 & command2
        wait


        is equivalent to



        command1 &
        command2
        wait


        ... which will work, but command2 will not be running in the background and wait will not be called until command2 has finished executing.






        share|improve this answer












        command1 &
        command2 &

        wait
        echo 'command1 and command2 have finished'

        command3 &
        command4 &

        wait
        echo 'command3 and command4 have finished'


        The call to wait will pause the script until all backgrounded tasks have finished executing.



        Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):



        ( command1; command2 ) &
        echo 'command1 and command2 are running'
        wait
        echo 'command1 and command2 have finished'


        In the above case, command1 and command2 will run in the background, but not concurrently with each other.




        Doing



        command1 & command2
        wait


        is equivalent to



        command1 &
        command2
        wait


        ... which will work, but command2 will not be running in the background and wait will not be called until command2 has finished executing.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 22 at 10:00









        Kusalananda

        103k13202319




        103k13202319






















            up vote
            1
            down vote













            The actual answer of my question was something like this, special thanks from @raman-sailopal



            command1 & command2
            wait
            echo "command 1 and 2 has finished"
            command3 & command4





            share|improve this answer




















            • That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
              – Kusalananda
              Jan 22 at 9:55














            up vote
            1
            down vote













            The actual answer of my question was something like this, special thanks from @raman-sailopal



            command1 & command2
            wait
            echo "command 1 and 2 has finished"
            command3 & command4





            share|improve this answer




















            • That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
              – Kusalananda
              Jan 22 at 9:55












            up vote
            1
            down vote










            up vote
            1
            down vote









            The actual answer of my question was something like this, special thanks from @raman-sailopal



            command1 & command2
            wait
            echo "command 1 and 2 has finished"
            command3 & command4





            share|improve this answer












            The actual answer of my question was something like this, special thanks from @raman-sailopal



            command1 & command2
            wait
            echo "command 1 and 2 has finished"
            command3 & command4






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 22 at 9:40









            Ebrahim Poursadeqi

            1135




            1135











            • That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
              – Kusalananda
              Jan 22 at 9:55
















            • That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
              – Kusalananda
              Jan 22 at 9:55















            That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
            – Kusalananda
            Jan 22 at 9:55




            That will work, but thu wait will only wait for command1 as command2 is not run as a background task. The same goes for command4.
            – Kusalananda
            Jan 22 at 9:55










            up vote
            0
            down vote













            command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"


            & runs commands simultaneously



            ; emulates a new line - i.e. will be run after completion



            && runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)






            share|improve this answer




















            • This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
              – Stephen Kitt
              Jan 22 at 9:45














            up vote
            0
            down vote













            command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"


            & runs commands simultaneously



            ; emulates a new line - i.e. will be run after completion



            && runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)






            share|improve this answer




















            • This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
              – Stephen Kitt
              Jan 22 at 9:45












            up vote
            0
            down vote










            up vote
            0
            down vote









            command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"


            & runs commands simultaneously



            ; emulates a new line - i.e. will be run after completion



            && runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)






            share|improve this answer












            command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"


            & runs commands simultaneously



            ; emulates a new line - i.e. will be run after completion



            && runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 22 at 9:31









            RobotJohnny

            438213




            438213











            • This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
              – Stephen Kitt
              Jan 22 at 9:45
















            • This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
              – Stephen Kitt
              Jan 22 at 9:45















            This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
            – Stephen Kitt
            Jan 22 at 9:45




            This doesn’t work: command1 will run in the background, the first echo will run as soon as command2 completes, regardless of whether command1 has finished. Likewise for command3.
            – Stephen Kitt
            Jan 22 at 9:45












             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418796%2frun-bunch-of-commands-and-wait%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?