Unlike Java, PHP and other languages, the process control of SH is not NULL, such as:
Copy Code code as follows:
<?php
if (Isset ($_get["Q"])) {
Search (q);
}
else {
Doing nothing
}
?>
You can't write this in Sh/bash, if the Else branch has no statement execution, don't write this else, like this:
Copy Code code as follows:
If condition
Then
Command1
Command2
...
CommandN
Fi
Of course, you can also write a line (for the terminal command prompt), like this:
Copy Code code as follows:
if test $[2*3]-eq $[1+5]; Then echo ' The two numbers are equal! '; Fi
The end of the fi is the if reverse spelling, you will encounter similar.
If Else format
Copy Code code as follows:
If condition
Then
Command1
Command2
...
CommandN
Else
Command
Fi
If else-if else format
Copy Code code as follows:
If Condition1
Then
Command1
Elif Condition2
Command2
Else
CommandN
Fi
The If Else statement is often used in conjunction with the Test command, as follows:
Copy Code code as follows:
NUM1=$[2*3]
NUM2=$[1+5]
if test $[num1]-eq $[num2]
Then
Echo ' The two numbers are equal! '
Else
Echo ' The two numbers are not equal! '
Fi
Output:
The two numbers are equal!