搜索
写经验 领红包
 > 育儿

用shell写一个简单的石头、剪刀、步的猜拳游戏

脚本内容如下:
$ cat game.sh需求:用shell脚本写一个石头、剪刀、步的游戏34;你出的拳是:$person&34;电脑出的拳是:$computer&用数字1、2、3分别模拟石头、剪刀、步echo &34;39;请出拳[1(石头) | 2(剪刀) | 3(步)]:&2.判断person是否为合法出拳,不是退出游戏if [ $person -ne 1 -a $person -ne 2 -a $person -ne 3 ];then        echo &39;        exitfi4.比较person 和 computer的值,判断输赢if [ $person -eq $computer ];then        often        echo &34;elif [ $person -eq 1 -a $computer -eq 2 ] || [ $person -eq 2 -a $person -eq 3 ] || [ $person -eq 3 -a $computer -eq 1 ];then        often        echo &34;else        often        echo &34;fi

在linux主机上运行脚本
 bash game.sh