shell脚本之猜数字

笑着哭i 提交于 2020-01-17 02:45:42

shell脚本之猜数字

[root@m01 scripts]# cat guess-number.sh
#!/bin/bash
num=`echo $[RANDOM%60]`


while :
do


read -p "input a number in 1-60:" num1;


if
    [[ $num1 -eq $num  ]]
then
    echo You are right!
    exit 0
elif
    [[ $num1 -lt $num ]]
then
    echo You input number is low!
elif
    [[ $num1 -gt $num ]]
then
    echo You input number is big!
fi
done

检查脚本

[root@m01 scripts]# sh guess-number.sh
input a number in 1-60:20
You input number is low!
input a number in 1-60:50
You input number is big!
input a number in 1-60:40
You input number is big!
input a number in 1-60:30
You input number is big!
input a number in 1-60:25
You input number is big!
input a number in 1-60:24
You are right!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!