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!

shell脚本之猜数字教程xiaobaiqifei发布了24 篇原创文章 · 获赞 0 · 访问量 307 私信 关注


标签: shell, 脚本, echo, input, number, 数字, num, big

相关文章推荐

添加新评论,含*的栏目为必填