Condition test Type in Bash script: integer test
String test
File test
Expressions for conditional tests: [Expression]
[[expression]] expression must have a space before and after it
integer test :-eq: Tests whether two integers are equal and equal to True
-ne: Test whether two integers are unequal, not equal to True
-ge: Tests whether a number is greater than or equal to another number
-le: ..... ..... Less than or equal to ....
-gt: ..... ..... Greater than..........
-lt: ......... Less than..........
The logical relationship between commands (between statements) in bash:
Logic with: && The result of the previous command execution is false, the second statement is no longer executed
Logical OR: | |, the previous command executes the result is true, the second statement is no longer executed
Logical non-:!
You can use logical symbols after a condition test to determine whether the second instruction executes
Determine the logical relationship between commands by using the control structure of the conditional judgment
eg:[expression] && statement1 | | Statement2
Indicates that if the test expression is true, statement 1 is executed, or statement 2 is executed
If control structure:
if judgment condition; then
Statement
Fi
if judgment condition; then
Statement1
Else
Statement2
Fi
Note: The return value type of the judging condition must be Boolean type
file test: -e/path/to/filename test file is present
-F test Specifies that the file is not a normal file
-D test Specifies whether the file is a directory file
-R tests whether the file has Read permissions
-W Tests if the file has write permissions
-X tests whether the file has Execute permissions
String Test: =
==
Equal and double equals, [string1 = string2] Tests whether two strings are equal
-N String tests whether the specified string is empty and Null is true
-S string tests whether the specified string is not empty and is not empty for true
This article is from the "Zxcvbnm Xuan ye" blog, please be sure to keep this source http://10764546.blog.51cto.com/10754546/1707597
Conditional test in Shell