Results 1 to 4 of 4

Thread: Order of commands for bash scripting

  1. #1
    Join Date
    May 2009
    Location
    Fareham, UK
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Order of commands for bash scripting

    I wish to make to bash script where two commands run simultaneously and a third command will run only once the first two have finished, I've been playing around with different bash shortcuts but can't seem to quite get it right, so for an example
    Code:
    sleep 60 &
    echo command1;
    echo command2
    How would I change this so the "sleep 60" timer will start and echo will print "command1" to screen immediately but the second echo will not print "command2" until at least the sleep timer is done and "command1" has finished (whichever is the last to finish)

    Thanks for any help
    Regards
    Mark
    Catch me on Freenode - imark

  2. #2
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Order of commands for bash scripting

    bash script where two commands run simultaneously and a third command will run only once the first two have finished,
    Code:
    !#/bin/bash
    command 1 &; 
    command 2 &;
    wait 
    command 3;
    edited:
    Last edited by fdrake; December 24th, 2012 at 10:15 AM.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  3. #3
    Join Date
    May 2009
    Location
    Fareham, UK
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Order of commands for bash scripting

    The first example waits for command1 to finish to execute command2, I tried changing the && to & just in case thats what you meant but then commands 1,2&3 all run at once, the second example is perfect though, I've not come across the wait command before but I can see it will be useful to know.

    Many thanks
    Catch me on Freenode - imark

  4. #4
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,909
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Order of commands for bash scripting

    i fixed the post.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •