Used
If/while
And so on;
Test
Command
Test Condition
, When the condition is
True
Returns
0
;
If
Test condition; then
If
[Condition]; then
#
Note the space,
TBD
Supported?
If 0
...
<=>
...
Fi
Fi
Test
Condition judgment, three types
1
) Value Comparison
-Eq-ge-GT-le-lt-ne
2
) String comparison:
=
! =
<> (
Note escape
)-N (
Non-empty string
)-Z (
Empty string or not
)
;
Test
Uppercase and lowercase letters are the same
Sort
Opposite
Eg: If ["A"/> "B"]; then
Eg: If [-n "$1"]; then
<=> ["$1"]
#$1
It must be caused. Otherwise, it will fail to be judged.
Eg: If [string1-A string2]; then
# String1/string2
True
Eg: If [string1-O string2]; then # string1
Or
String2
True
3
) File comparison:
-D File
# Directory,
File
Is it a directory?
-E
# Exist,
File
Exist?
-F
# File
,
An exist File
-R
# Readable
-S
# Not
Empty
-W
# Writable
-X
# Executable
, And
Current User
You must have the execution permission.
-O
# Owered
By current user
-G
#
The default file user group is
Current User Group
File1-nt file2
# File1 new than file2
File1-ot file2
# Old
The above comparison will return a failure if the file does not exist. Therefore, you can determine whether the file exists before executing other comparisons;
Composite condition comparison
Similar
C
:
[Cond1] & [cond2] | [
Cond3]
If [
'A'/<'B'] & ['A'/<"C"] | ['A'/<'A'
]; Then
Advanced features:
A mathematical expression in a double parentheses table. It can also be used for mathematical computation,
If ($ A ** 2> 90 ))
The regular expression can be used to provide the pattern matching function,
If [[$ A = r *]
TBD
: How does one express non-logical?