In determining the size of a value in addition to (()) can be used in the form of [] but can not use;, <, = such a symbol, to use-LT (less than),-GT (greater than),-le (less than equals),-ge (greater than or equal),-eq (equals),-ne (not equal) 。
If statement
if Judgment statement; Then
Command
Fi
If,else statements
if Judgment statement; Then
Command
Else
Command
Fi
If Elif statement
If Judgment statement one; Then
Command
Elif Judgment Statement two; Then
Command
Else
Command
Fi
Three examples:
[email protected] ~]# cat if1.sh
#/bin/bash
Read-p "Input your Source:" A
If [$a-lt];then
echo "You did notpass the exam"
elif [$a-ge]&&[$a-le 85]; Then
echo "You pass the exam"
Else
echo "Your source is very high"
Fi
If statement can determine file attributes and permissions
-E: Determine if a file or directory exists
-D: Determine if the directory is not present and whether it exists
-F: Determine if the file is normal and exists
-R: Determine if the document has Read permissions
-W: Determine if Write permission is available
-X: Determine if executable
-Z: To determine if the variable is empty if [-Z $a] is empty is true.
When you use the If judgment, the specific format is:
If [-e filename]; Then
Example:
[Email protected] ~]# if [-d/home/]; then echo OK; Fi
Ok
This article from the "title" blog, declined reprint!
Shell-based if statement