调用RANDOM值,以3取余。
num=$[RANDOM%3] //以三个数字0、1、2代表计算机出拳手势
echo "1.剪刀"
echo "2.石头"
echo "3.布"
read -p "输入数字选择出拳" select //以不同的数字代表case语句中的不同模块
case $select in
1)
if [ $num -eq 0 ];then
echo "计算机选择了布"
echo "Conratulations!!!you win!!!"
elif [ $num -eq 1 ];then
echo "计算机也选择了剪刀"
echo "dogfall"
elif [ $num -eq 2 ];then
echo "计算机选择了石头"
echo "Sorry,you loss~~"
fi;;
2)
if [ $num -eq 0 ];then
echo "计算机选择了剪刀"
echo "Conratulations!!!you win!!!"
elif [ $num -eq 1 ];then
echo "计算机也选择了石头"
echo "dogfall"
elif [ $num -eq 2 ];then
echo "计算机选择了布"
echo "Sorry,you loss~~"
fi;;
3)
if [ $num -eq 0 ];then
echo "计算机选择了石头"
echo "Conratulations!!!you win!!!"
elif [ $num -eq 1 ];then
echo "计算机也选择了布"
echo "dogfall"
elif [ $num -eq 2 ];then
echo "计算机选择了剪刀"
echo "Sorry,you loss~~"
fi;;
*)
echo "输入错误!!!"
esac