Conditional constructs – if else
We use the if command to check the pattern or command status and accordingly we can make certain decisions to execute scripts or commands.
The syntax of the if conditional is as follows:
if command
then
command
command
fiFrom the preceding syntax, we can clearly understand the working of the if conditional construct. Initially, if will execute the command. If the result of command execution is true or 0, then all the commands that are enclosed between then and fi will be executed. If the status of command execution after if is false or nonzero, then all the commands after then will be ignored and the control of execution will directly go to fi.
Let's learn another variation of if constructs.
Syntax:
if command
then
command
command
else
command
fiIn the preceding case if the command after if is successfully executed or the status variable ? content is 0, then all the commands after then will...