-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
demo11
executable file
·62 lines (48 loc) · 1.02 KB
/
demo11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
a=24
b=47
if [ "$a" -eq 24 ] && [ "$b" -eq 47 ]
then
echo "Test #1 succeeds."
else
echo "Test #1 fails."
fi
# 错误: if [ "$a" -eq 24 && "$b" -eq 47 ]
#+ 这会尝试执行' [ "$a" -eq 24 '
#+ 然后会因没找到匹配的']'而失败.
#
# 注意: if [[ $a -eq 24 && $b -eq 24 ]]也可以.
# 双方括号的if-test比
#+ 单方括号的结构更灵活.
# (第17行和第6行的"&&"有不同的意思.)
# 多谢Stephane Chazelas指出这一点.
if [ "$a" -eq 98 ] || [ "$b" -eq 47 ]
then
echo "Test #2 succeeds."
else
echo "Test #2 fails."
fi
# -a和-o选项提供
#+ 混合条件测试另一个选择.
# 多谢Patrick Callahan指出这一点.
if [ "$a" -eq 24 -a "$b" -eq 47 ]
then
echo "Test #3 succeeds."
else
echo "Test #3 fails."
fi
if [ "$a" -eq 98 -o "$b" -eq 47 ]
then
echo "Test #4 succeeds."
else
echo "Test #4 fails."
fi
a=rhino
b=crocodile
if [ "$a" = rhino ] && [ "$b" = crocodile ]
then
echo "Test #5 succeeds."
else
echo "Test #5 fails."
fi
exit 0