Wait for .sh script to finish before executing another .sh script?

10,105

Simply use the && connector (i.e. a compound-command):

./script1.sh && ./script2.sh

But please consider that in this case the second script will be executed only if the first returns a 0 exit code (i.e. no error). If you want to execute the sequence whatever the result of the first script, simply go:

./script1.sh ; ./script2.sh

You can test the behaviour of the two connectors:

$ true && echo aa
aa
$ false && echo aa
$ false ; echo aa
aa
Share:
10,105
STiGYFishh
Author by

STiGYFishh

Updated on June 05, 2022

Comments

  • STiGYFishh
    STiGYFishh almost 2 years

    Basically I want to run two shell scripts but I want one of the scripts to run only after the other script has finished how would I go about doing this? I've read a bit about Until and While but I don't quite understand how I would use them. I'm sure this is very simple however I am very new to Linux.

  • Keith Thompson
    Keith Thompson over 9 years
    The question didn't say anything about running the second script only if the first succeeds. The ./script1.sh ; ./script2.sh should probably be mentioned first, with && as an afterthought. And you don't need a semicolon; just put the two commands on separate lines.