str
| Operator |
Describe |
Example |
File comparison Operators |
| [-e file] |
file exists, it is true |
eg:[-e/etc/passwd] |
| [-d file] |
|
|
| [-f file] |
|
|
| [-l file] |
|
eg:[-L /etc/passwd ] |
| [-r file] |
is readable, true |
/etc/passwd ] |
| [-w file] |
is writable, true |
/etc/passwd ] |
| [-x file] |
is executable, true |
/etc/passwd ] |
| [file1-nt File2] |
file1 is newer than file2 , then true |
eg: [ -nt /ETC/PASSWD ] |
| [file1-ot File2] |
file1 is older than file2 , then true |
eg: [/etc/passwd ] |
string comparison operators |
[-Z string] or [-Z variable] |
True if str length is zero |
Eg:[-Z "$STR"] |
| [-n ] or [-n variable] |
| if length is nonzero
eg:[-N "$tr"] |
| [ string 1= str1 is the same as str2 , then true |
eg:["$str" = "This is a string"] |
| [ string 1!= 2] |
true |
str1 differs from str2 7px;border:1px inset, "height=", "> eg:["$str"! = "this is a string "] |
Arithmetic comparison operators |
[Num1-eq num2] |
Equals |
eg:[1-eq $num] |
| [num1-ne num2] |
is not equal to |
eg:[2-ne $num] |
| [num1-lt num2] |
less than |
|
| [num1-le num2] |
less than or equal to |
|
| [num1-gt num2] |
greater than |
|
[Num1-ge num2] |
Greater than or equal to |
eg: [6-ge $num] |
This article is from the "binary in the Network" blog, be sure to keep this source http://grivel.blog.51cto.com/979453/1851020
The integer operator file test character operation for bash in Linux is attached