使用系统自带变量RANDOM提取随机数(1-100),使用while :制作死循环。
#! /bin/bash
number=$[$RANDOM%100 ] 系统自带变量RANDOM
i=0 设置变量 i=0 后面用于提示你猜对几次
while : 死循环结构,while后do开头,done结尾
do
read -p "请输入数字1~100" cai read -p (由这个开关项给出提示信息),后面可以接提示符号
let i++ 自增命令
if [ $cai -eq $number ];then
echo "你猜对l"
echo "你猜了$i次"
elif [ $cai -gt $number ];then
echo "你猜大了"
else
echo "你猜小了"
fi
done
while
猜你喜欢
转载自blog.csdn.net/weixin_42628856/article/details/81319448
今日推荐
周排行