Currently I have a script.sh file with the following content:

wget -q http://exemple.com/page1.php;
wget -q http://exemple.com/page2.php;
wget -q http://exemple.com/page3.php;

I want to execute the commands one by one, when the previous finishes. Am I doing it in the right way? I've never worked with Linux before and tried to search for it but found no solutions.

  • 1
    terdon's answer below is excellent but you can drop the semi-colons in the version you've shown above as well as commands are executed in order in the script, each on its own line. The semicolon is redundant unless you put all the commands on one line. Commented Feb 12, 2015 at 17:57

2 Answers 2


Yes, you're doing it the right way. Shell scripts will run each command sequentially, waiting for the first to finish before the next one starts. You can either join commands with ; or have them on separate lines:

command1; command2



There is no need for ; if the commands are on separate lines. You can also choose to run the second command only if the first exited successfully. To do so, join them with &&:

command1 && command2


command1 &&

For more information on the various control operators available to you, see here.


In a repetitive case like this I recommended using a for loop.

for P in {1..3} ; do wget -q http://exemple.com/page${P}.php ; done

This is a one-line version suitable for the command line but can also be used in a script. The braces around the variable name are needed when embedding a variable into a string without whitespace.

The loop not only sends the requests in order, but is easier to tweak and reuse when needed, without as many worries about typos.

  • Adding with info of the top-vote, you can use && instead of ; - right before done - to make sure that the next command runs after the last one finished with success.
    – Timo
    Commented Feb 27 at 9:09

Not the answer you're looking for? Browse other questions tagged .