First, the arithmetic operation
Copy Code code as follows:
second, the relationship operation
Copy Code code as follows:
Third, the test operation
Testing command: Test [] [[]] [()]
1. test file status
Copy Code code as follows:
-D Directory
-B Block Equipment
-S file length > 0, Non-empty
-F Regular Documents
-W can write
-L Symbolic connection
-u file has suid bit settings
-R Readable
-X Executable
such as: [-w tmp.txt] test file tmp.txt is writable
2. String test
Copy Code code as follows:
= Two strings equal
!= Two strings Not equal
-Z Empty string
-N Non-empty string
$ var1= ' abc '
$ Var2= ' 123 '
$ ["$VAR 1" = "$VAR 2"]
$ echo $?
1
3. Test values
Copy Code code as follows:
-eq equals
-ne is not equal to
-GT Greater than
-lt less than
-ge is greater than or equal to
-le less than or equal
4. Expand test symbols [[]] (())
Copy Code code as follows:
# [[2 > 10]] # result error
# echo $?
0
# ((2 >10)) The result is correct
# echo $?
0
# [[[' AA ' = ' AA ']]
# echo $?
0
# ("AA" = "AA") #结果错误
# echo $?
1
Iv. Conclusion
Compare numbers, using (())
other tests using [[]]
mixed tests containing numeric comparisons, using standard syntax