Conditional test!

I. Overview of the test condition
1, the effect of the test conditions: the determination of the specific conditions, it has been decided to implement operations.
2, Test Method:
Method 1: Conditional Expression Test
Method 2: [Conditional Expression] (commonly, note "[]" and the conditional expression directly retains at least one space)
class 3, the conditions tested:
(1) document test
1> format: [operator file or directory]
2> common test operators:
-d: tests for whether the directory (directory)
-e: test directory or file exists (exist a)
test whether a file (: -f file)
-r: test the current user is readable (the read)
-w: testing whether the current user can write (the write)
-x: to test whether the current user can perform (Excute)
-s: the test file size is nonzero is true ( if the file is non-empty, true)
-u: test whether the SUID attribute
-g: test whether SGID attributes
-k: test whether the sticky bit the sticky bit attribute
-nt: test whether the first file than the second a new file (the Then new)
-ot: the first test whether a file is older than the second file (the Then old)
-ef: test whether the first file with the second file is the same file (file link like )

[root@localhost ~]# [ -d /a ]
[root@localhost ~]# echo $?

0

[root@localhost ~]# [ -e /p ]
[root@localhost ~]# echo $?
1

===================================================================

Integer test

-eq: equal (Equal)
-ne: is not equal to (Not Equal)
-gt: greater than (the Greater Than)
-LT-: less than (Lesser Than)
-ge: greater than or equal to (the Greater or Equal)
-le: less than or equal to ( Lesser or Equal

[root@localhost ~]# [ 1 -eq 0 ]
[root@localhost ~]# echo $?
1

[root@localhost ~]# [ 1 -ne 1 ]
[root@localhost ~]# echo $?
1

[root@localhost ~]# [ 1 -gt 1 ]
[root@localhost ~]# echo $?
1

[root@localhost ~]# [ 0 -lt 1 ]
[root@localhost ~]# echo $?
0

[root@localhost ~]# [ 0 -ge 1 ]
[root@localhost ~]# echo $?
1

[root@localhost ~]# [ 0 -le 1 ]
[root@localhost ~]# echo $?
0

 

Guess you like

Origin www.cnblogs.com/cxm123123form/p/11445066.html