This question already has an answer here:

Is it possible to enter the next command line like this:

command1 ; command2;

After validating command1?

For example I do:


And it takes a long time! I want to say: after this command: do ./myprogram So I can go take a coffee, and not just wait until it finishes to launch the next command.

marked as duplicate by jokerdino Jun 9 '16 at 17:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    All you should have to do is to add && between your commands. That should tell the second command to wait for the first command to complete. – Terrance Jun 7 '16 at 21:52
  • Ok @Terrance but when a validate (press enter) command 1 How can I add the && command2 if I forget to add the command 2? – Fractale Jun 7 '16 at 22:02
  • @perecastor just have a look at the marked duplicate question or my answer below. – Videonauth Jun 7 '16 at 22:04
  • Sorry about that, I get what you are asking. Look in the duplicated answer and look at David Foerster's answer. He shows to suspend the app, then the fg command would bring it back to the foreground, then you add the ; after then type in your last command. Once you press enter, it will bring your long running command back to the foreground and complete, then run your second command should run automatically. Hope that helps! – Terrance Jun 7 '16 at 22:19

Sure you can do that, simply add an && or || at the ending of the line depending you want the action be done if the previous command succeeds or fails. So for the following example I use the usual upgrade stuff but it works with almost every command.

# an example upgrade script, call with sudo ./scriptname.sh
apt-get update &&
apt-get -y dist-upgrade &&
apt-get -y autoremove &&
apt-get clean

This would be for a script which only forwards on succession of the commands before. note that the last line has no &&, that is because it would throw you an error if it where there, because there is no next command to jump to.

Now an example for a failure, shall we? Taking again the same example but I want my computer to tell me how silly my action was (kidding):

# an example upgrade script, call with sudo ./scriptname.sh
apt-get update &&
(apt-get -y dist-upgrade &&) || echo "THIS was not working right"
apt-get -y autoremove &&
apt-get clean

So this would in case the command fails output something, for more reading on the bash shell scripting you can visit the links I included here:



  • It seems that he is a newbie and this answer will be too complex for him to grasp – rancho Jun 7 '16 at 23:17
  • For exactly this reason I included the links for further reading material, up to that the more throughout an answer is the more easy it gets to understand, and as you could see with the comments on your answer, it raised new questions for clarity. – Videonauth Jun 7 '16 at 23:21

For that you require to put && between the consecutive commands so that they execute one by one

  • Ok @rancho but when a validate (press enter) command 1 How can I add the && command2 if I forget to add the command 2? – Fractale Jun 7 '16 at 22:04
  • Your question is not clear, just type all the commands one by one with && in between them and at the end of the line press enter. The commands will automatically execute one by one without the need of your attention – rancho Jun 7 '16 at 22:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.