猜拳xshell版

#!/bin/bash
while :
do
#获得用户出拳read -p
read -p "请按提示出拳1.剪刀2.石头3.布" person
#获得计算机随机出拳
com=$((RANDOM % 3 +1))
if [ $person == "剪刀" ]
        then
     person=1
elif [ $person == "石头" ]
        then
        person=2
elif [  $person == "布" ]
        then
        person=3
else
        echo "请按提示猜拳"
fi
#进行判断论输赢
if  [ $person = 1 -a $com = 2  ] || [ $person = 2 -a $com = 3 ] ||  [ $person = 3 -a $com = 1 ]
        then
        echo "person win"
elif [ $person = $com ]
        then
        echo "平局"
else
        echo "com win"
fi
read -p "还要继续吗?【n/N退出,任意键继续】" choice
if [ $choice == "n" ] || [ $choice == "N" ]
        then
        exit
else
        clear
fi
done
       

你可能感兴趣的:(linux,运维)