common syntax for conditional testing:
| Syntax format |
Description |
| [< test expression >] |
[] has at least one space between the boundary and the content |
| [[ < Test expression > ]] |
[[] There is at least one space between the boundary and the content |
Note that the:&&, | |, >, < operators can be applied to [[]], but not to [], and in [] generally use-A,-O,-GT (for integers) instead of the above operators
Commonly used file-judging operators
| -D files, all of which are spelled as directory |
The file exists and is true for the directory, that is, the test expression is set |
| -f file, F's full spell file |
File exists and is normal file True, that is, the test expression is set |
| -e file, the full spell for exist |
The existence of the file is true, that is, the test expression is established. -E does not distinguish between a directory or a file |
| -r/w/x file, r/w/x's full spell is read/write/executable |
File exists and readable/writable/executable, i.e. test expression established |
| -S file, S is fully spelled as size |
True if the file exists and the file size is not 0 |
| -l file, L's all spelled as Link |
The file exists and is true for the linked file |
| F1-nt F2,nt's full spell is newer than |
File F1 newer than file F2 true |
| F1-ot F2,ot's full spell is older than |
File F1 is true compared to file F2 old |
Commonly used string test expressions
| -N "String" |
True if the length of the string is not 0 |
| -Z "string" |
True if the length of the string is not 0 |
operator comparison
Comparison symbols used in test and []
|
Comparison symbols used in (()) and [[]] |
Description
|
| -eq |
= = or = |
Equals |
| -ne |
!= |
Not equal to |
| -gt |
> |
Greater than |
| -ge |
>= |
Greater than or equal |
| -lt |
< |
Less than |
| -le |
<= |
Less than or equal |
-A
|
&& |
And |
| -O |
|| |
Or |
| ! |
! |
Non - |
Conditional judgment and comparison of shell scripts