After you understand the basic statements, you need to implement your own ideas. Start to do some judgment on the condition of learning.
Test
Test is an expression of a shell program that can be conveniently tested with strings, file states and numbers, and tests [expressions] By combining the conditional statements provided by the shell. The operators represented by an expression are: string operators, numeric operators, logical operators, and file operators. Among them, the file operator is a shell-specific operator, because the shell variables are strings, in order to achieve the purpose of the operation of the file, thus providing an operator.
1. The comparison symbols for strings are: = Compare two strings for the same,!= comparison is different,-n compares whether the string length is greater than the length of the 0-z comparison string is equal to 0.
Tip: When test handles variables with spaces, it is best to enclose the variable in quotation marks.
2. Comparison of numbers
-eq is equal,-ge is greater than or equal to-le less than or equal to-ne not equal to-gt greater than-lt less than
3. Logic Test
。 Logical value contrary to a logical value
-a equivalent to &&-o equivalent | |
4. File operation
D exists and is a directory. -F exists and exists for file L and is a symbolic link -R exists and is readable -s and has a length of 0 -W exists and writable, -X exists and can be executed.