#!/bin/bash#author: The Adventures of Tintin (Jacob) #定义数组, save all the possibilities of Punch game= (stone scissors cloth) num=$[random%3]computer=${game[$num]}# Get the punch of a computer by random number # The possibility of a punch is saved in an array, game[0],game[1],game[2] is 3 different possible echo "Please choose your punch gesture according to the following tips" echo "1. Stone "echo " 2. Scissors "echo " 3. Cloth " read -p " Please select 1-3: " person# prompts the user to punch, According to the prompt Punch can be # again through the case statement to determine whether the user input value is 1 or 2 or 3, according to different inputs to determine the different results case $person in1) if [ $num -eq 0 ];then echo "Draw" elif [ $num -eq 1 ];then echo "You Win" else echo "Computer wins" fi;; 2)    &NBsp; if [ $num -eq 0 ];then echo "Computer wins" elif [ $num -eq 1 ];then echo "Draw" else echo "You Win" fi;; 3) if [ $num -eq 0 ];then echo "You Win" elif [ $num -eq 1 ];then echo "Computer Win"        ELSE&NBsp; echo "Draw" fi;; *) echo "must enter 1-3 number" Esac
This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1967775
Shell script game: scissors stone Cloth