shell 现1-100的猜数字游戏

#!/bin/bash


NR=$[RANDOM%100];
reg='[1-9]|[0-9]{2}|100';
echo $NR;
while : 
do
read -p "input a number in 1 to 100 :" inum;
if [[ ! "$inum" =~ $reg ]]; then
echo "input err!";
continue;
fi
if [[ $inum -gt NR ]]; then
echo "too big";
continue;
fi
if [[ $inum -lt NR ]]; then
echo "too small";
continue;
fi

if [[ $inum -eq NR ]]; then
echo "yes";
break;
fi
done

猜你喜欢

转载自blog.csdn.net/qq_38572383/article/details/80915587