猜数字
shell随机数:写一个猜数字脚本,数字范围是1-100,定制计数器,每次猜完都要告诉用户猜大或猜小了,如果猜对了跳出脚本并输出计数器的值
!/bin/bash
Description:
Author: Bai Shuming
Created Time: 2019/05/29 05:46
随机猜数字
num=echo $((RANDOM%100+1))
count=1
echo -n "请输入一个数字: "
read num1
if [ num1 ];then
echo "对了,随机数字是:count次"
elif [ num1 ];then
echo "小了,继续"
let count++
else
echo "大了,继续"
let count++
fi
while [ num1 ]
do
echo -n "请输入一个数字: "
read num1
if [ num1 ];then
echo "对了,随机数字是:count次"
elif [ num1 ];then
echo "小了,继续"
let count++
else
echo "大了,继续"
let count++
fi
done
网友评论