#!/bin/bash
num=$(($RANDOM%100+1))
TIME=1
while true
do
if [ $TIME -gt 3 ];then
read -ep "你猜错的次数超过3次,是否继续(y/n)" ASK
if [ $ASK == y ];then
TIME=1
else
exit
fi
else
read -ep "请输入一个数字:" NUM
if [ $NUM -gt $num ];then
echo "你猜的大了"
let TIME++
elif [ $NUM -lt $num ];then
echo "你猜的小了"
let TIME++
elif [ $NUM -eq $num ];then
echo "恭喜你猜对了"
exit
fi
fi
done
shell脚本-猜数字
最新推荐文章于 2024-06-20 16:30:42 发布