Thursday, January 7, 2010

Running multiple commands

Sometimes as a system administrator, you will need to run multiple commands in sequence. One of the more classic example is ./configure followed by make and then make install. How do we do it?

Method 1 "./configure; make; make install"
  • The semi-colon causes the commands to be executed in sequence
  • If one of the intermediate commands fails, the subsequent commands after the failed command will still be executed and the error may be hidden in the output.
Method 2: "./configure && make && make all"
  • && represent if the ./configure and make and make all are true without error, the entire commands will run. If there is one error in either of the commands, the subsequent command will not run
Method 3: "./configure || ./setup"
  • || represent "or". If the first command fail to run, only then the 2nd command will run. It is useful for alert for example "./configure || echo "Configuration Error" "

No comments: