1. Numerical test
Parameters |
Description |
-eq |
Equals is True |
-gt |
is greater than true |
-lt |
is less than true |
-nq |
Not equal to True |
-ge |
Greater than or equal to true |
-le |
is less than or equal to true |
Example:
num1=num2=if test $[num1] eq $[num2]then Echo ' two numbers equal 'else echo' two numbers are unequal ' fi
Output: Two numbers equal
2. String Test
Parameters |
Description |
= |
Equals is True |
! = |
Not equal to True |
-Z |
String length is zero for true |
-N |
String length is not 0 bit true |
Example:
string1='liupf'string2='liupf'if test string1=string2then echo' two strings equal 'Else echo' two strings unequal 'fi
Output: Two strings equal
3. File test
Parameters |
Description |
-E File name |
File exists as true |
-W file name |
File exists and can be written as true |
-R file name |
File exists and can be read as true |
-X file name |
File exists and can be executed as true |
-S file name |
File exists and has at least one string |
-D file name |
For a directory to be true |
-F file name |
For an ordinary file to be true |
-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 |
Example:
CD/binif test-e./bashthen echo' file already exists! ' Else Echo ' file does not exist! ' fi
Output: File already exists
Shell Basics Learning (v) Test command