shell脚本之猜数字

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!
发布了24 篇原创文章 · 获赞 0 · 访问量 305

猜你喜欢

转载自blog.csdn.net/xiaobaiqifei/article/details/104010331
今日推荐