1) What is the function of the IF condition control statement?
The shell script is also a weak scripting language and supports if conditional control statements.
2) If the structure syntax
Single Branch
If
Then
Fi
Dual Branch
If
Then
Else
Fi
Multi-Branch
If
Then
Elif
Then
Else
Fi
3) Scope of application
Determine if business services are functioning properly
Example
Determine if the LFTP is installed if not installed
VI install_lftp.sh
#!/bin/bash
Rpm-qa |grep lftp 1>/dev/null
If [$?-ne 0];then # #若上调命令执性不成功说明没有安装lftp, install
Yum-y Install lftp &>/dev/null &&echo "lftp installed."
Fi
: Wq
Expand "" One of the usages
When the variable is a number, it is to be judged by the numbers, and the state of the software is analyzed by the result.
Integer comparison
-eq equals, such as: if ["$a"-eq "$b"]
-ne not equal to, such as: if ["$a"-ne "$b"]
-GT greater than, such as: if ["$a"-gt "$b"]
-ge greater than equals, such as: if ["$a"-ge "$b"]
-lt less than, such as: if ["$a"-lt "$b"]
-le less than equals, such as: if ["$a"-le "$b"]
Linux self-study _shell script if detailed