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
|
[root@yonglinux ~]
# cat guess.sh
#!/bin/bash
#guess number game;
n=$[$RANDOM%100]
while
:
do
read
-p
"please input a number: "
n1
n2=`
echo
$n1 |
sed
's/[0-9]//g'
`
if
[ ! -z $n2 ]
then
echo
"your number is not a number."
continue
fi
if
[ $n1 == $n ]
then
echo
"you are all right."
break
elif
[ $n1 -gt $n ]
then
echo
"bigger."
continue
else
echo
"smaller."
continue
fi
done
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@yonglinux ~]
# sh guess.sh
please input a number: 56
bigger.
please input a number: 33
bigger.
please input a number: 15
bigger.
please input a number: 7
smaller.
please input a number: 10
bigger.
please input a number: 8
smaller.
please input a number: 9
you are all right.
本文转自 模范生 51CTO博客,原文链接:http://blog.51cto.com/mofansheng/1668683,如需转载请自行联系原作者
|