Compare the size of two integers in a conditional expression with a comparison of two strings for equality, using a different operator.
(1) string comparison
-N STRING #字符串长度如果为非0则返回真
-Z STRING #字符串长度如果为0则返回真
STRING1 = STRING2 #两个字符串相同则返回真
STRING1! = STRING2 #两个字符串不相同则返回真
(2) Numerical comparison
where Arg1 and arg2 can be either a positive integer or a negative integer, but not a floating-point number.
Arg1-ne arg2 #arg1不等于arg2
Arg1-eq arg2 #arg1等于arg2
Arg1-lt arg2 #arg1小于arg2
Arg1-le arg2 #arg1小于等于arg2
ARG1-GT arg2 #arg1大于arg2
Arg1-ge arg2 #arg1大于等于arg2
Important
(1) The Shell's built-in test commands [and] need spaces on both sides.
(2) in the Test command [], use-eq to compare two strings for equality, compare the size of two integers (greater than, less than, equal to), and compare two strings for equality, using different operators.
Shell Process Control
If,elif
(1) If condition
Then
Command
Fi
(2) If condition
Then
Command1
Else
Command2
Fi
(3) If condition
Then
Command1
Elif condition
Then
Command2
Elif condition
Command3
Fi
2.case
Case Word in
PATTERN1)
Command1
;;
PATTERN2)
Command2
;;
PATTERN3)
Command3
;;
*)
Command4
;;
Esac
3.while
While condition
Do
Command
Done
4.until
Until condition
Do
Command
Done
5.for
For name in words
Do
Command
Done
6.select
Select name in words
Do
Commands
Done
7.break
8.continue
Linux Process Control and variable comparison