The string is compared to the integer type, because the ABCD and other characters are not 0123 when the program tries to turn to binary, the conversion cannot be completed, so the operation used for the numeric comparison cannot be used for the string;
However, the integer type as a string comparison, 0123 of these values can be fully converted to ASCII code and the original two integer equal to ASCII code or equal or unequal, so can be used for the comparison of strings can also be used for the comparison of the integer type.
1. Only applicable to numeric comparisons
This type of operation will take both sides of the variable as an integral type for the addition and subtraction operation, the string ABCD cannot be done by integral type operation, so this type cannot be used for string comparison
Parameters |
Description |
-eq |
Equals is True |
-ne |
Not equal to True |
-gt |
is greater than true |
-ge |
Greater than or equal to true |
-lt |
is less than true |
-le |
is less than or equal to true |
2. Comparisons for strings (also available for numeric comparisons)
Parameters |
Description |
== |
Equality is True |
!= |
Not Equal is true |
3. String Test operations
Parameters |
Description |
-Z String |
True if the length of the string is zero |
-N String |
True if the length of the string is nonzero |
4. File Test Operations
Parameters |
Description |
-E File name |
True if the file exists |
-R file name |
True if the file exists and is readable |
-W file name |
True if the file exists and is writable |
-X file name |
True if the file exists and is executable |
-S file name |
True if the file exists and has at least one character |
-D file name |
True if the file exists and is a directory |
-F file name |
True if the file exists and is a normal file |
-C file name |
True if the file exists and is a character-specific file |
-B file Name |
True if the file exists and is a block special file |
Description
1. In various operations, the operation of the test command is equivalent to the square brackets
2. When assigning a value, there are no spaces on either side of the equal sign, and spaces are required on both sides of the comparison or test
3. The shell defaults to character arithmetic, and if you want to calculate the value, add expr to the front, such as: expr $var 1 + $var 2
4. The shell file contains only "." Commands, and the command can only contain a single file at a time (with * for all files in the folder, of course) and cannot contain a folder; the!includedir and #includedir do not exist. It should be the included function that the program implements itself
5. "." Execution in the shell affects the environment of the shell, but only in scripts that affect the environment in the script does not affect the environment of the current shell;
Reference:
Http://www.runoob.com/linux/linux-shell-test.html
Linux shell numeric comparisons and string comparisons and correlation