February 13 2018 Tuesday
Weather : sunny
1、需求: 写一个猜数字脚本,当用户输入的数字和预设数字(随机生成一个0-100的数字)一样时,直接退出。否则让用户一直输入,并且提示用户的数字比预设数字大或者小。[root@Dasoncheng sbin]# cat e.sh #!/bin/bashm=`echo $RANDOM`nn=$[$m%100]while :;do read -p "Please input a number(0-100): " n n2=`echo -n $n |sed 's/[0-9]//g' |wc -c |awk '{print $1}'` if [ $n2 -ne 0 ]; then echo "Please input a number !" continue fi if [ $n -lt 0 ] || [ $n -gt 100 ]; then continue else if [ $n == $nn ]; then break elif [ $n -gt $nn ]; then echo "the number you input is so large!" continue else echo "the number you input is so little!" continue fi fidoneecho "congruation,you are right!"