[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
[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.
本文出自 “模范生的学习博客” 博客,请务必保留此出处http://mofansheng.blog.51cto.com/8792265/1668683
原文地址:http://mofansheng.blog.51cto.com/8792265/1668683