Copyright(c) by Galaxy CD – http://www.galaxycd.com
52
test
-w
filename
0
neáu file toàn taïi vaø ghi ñöôïc
test
-x
filename
0
neáu file toàn taïi vaø chaïy ñöôïc
test
-s
filename
0
file toàn taïi vaø khoâng roãng (not empty)
[file1 -ef
file2]
0
file1 vaø file2 lieân keát vôùi nhau
[file1 -nt
file2]
0
neáu file1 môùi hôn file2
[file1 -ot
file2]
0
neáu file1 cuõ hôn file2
[-b
filename]
0
file toàn taïi vaø ñoïc ghi theo block
[-c
filename]
0
file toàn taïi vaø ñoïc ghi theo kyù töï
+So saùnh giöõa caùc soá:
Cuù phaùp nhö sau:
test
value1 operator
value2
Caùc toaùn töû so saùnh (operator) coù theå duøng:
-eq
baèng (equal to)
-ne
khoâng baèng (not equal to)
-gt
lôùn hôn (greater than)
-ge
lôùn hôn hoaëc baèng (greater or equal to)
-lt
nhoû hôn (less than)
-le
nhoû hôn hoaëc baèng (less or equal to)
Thí duï:
$
test “$A” -eq
“$B”
true neáu giaù trò cuûa bieán A baèng giaù trò cuûa bieán B
+Kieåm tra caùc xaâu kyù töï:
[“str1” = “str2”]
ñuùng neáu str1 baèng str2
test “str1” != “str2”
ñuùng neáu str1 khaùc str2
test
-z
“$A”
ñuùng neáu xaâu $A roãng
test
-n
“$A”
ñuùng neáu xaâu $A khoâng roãng
Thí duï:
$
test “$LOGNAME”
!=
“user1”
+Keát hôïp caùc ñieàu kieän:
Caùc toaùn töû so saùnh coù theå keát hôïp vôùi:
-a
vaø (and)
-o
hoaëc (or)
!
ñaûo (negation)
\(…\)
goäp (grouping)
Thí duï:
$
test \(-r file1 -o -r file2 \) -a -w file3
ñuùng neáu: