Additionally, the exit status is stored in the $? variable.
To execute two or more commands in sequence regardless of the failure/success of the previous command, you can use a single semi colon ";" in between of your commands. For example:
Code: Select all
$ mycommand1 ; mycommand2
you can test this with these 2 commands by using:
Code: Select all
false ; whoami
true ; whoami
[Logical OR] OR logical operator
To execute the next command in condition of when the first command fails, you can use logical OR operator which is double pipes "||".
Code: Select all
$ mycommand1 || mycommand2
you can test this with these 2 commands by using:
Code: Select all
false || whoami
true || whoami
To execute the next command in condition of when the first command is successfully accomplished, you can use logical AND operator which is double ampersand "&&". Look at this example:
Code: Select all
$ mycommand1 && mycommand2 && myucommand
Code: Select all
./configure && make && make install
In this last example, mycommand2 will only be executed when mycommand1 is successful. etc..
I am not a programmer. I am a "Machete Coder" (Chop and Hack / Trial and Error methods)
So don't hold me responsible! As will all things Linux, verify it for yourself!
References:
Command Lists Logical Operators
Advanced Bash-Scripting Guide
Enjoy!