0

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

command1 ; command2;

After validating command1?

For example I do:

make 

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.

belacqua
  • 23,540
Fractale
  • 133

2 Answers2

1

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.

#!/bin/bash
# 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):

#!/bin/bash
# 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:

http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html

http://mywiki.wooledge.org/BashGuide

Videonauth
  • 33,815
0

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

rancho
  • 4,136