#!/bin/bash ww=(剪刀 石頭 布) num=$[RANDOM%3] computer=${ww[$num]} echo "1.剪刀" echo "2.石頭" echo "3.布" read -p"輸入1-3:" mt case $mt in 1) if [ $num -eq 0 ] then echo "平局" elif [ $num -eq 1 ] then echo "你贏" else echo "計算機贏" fi ;; 2) if [ $num -eq 0 ] then echo "你贏" elif [ $num -eq 1 ] then echo "平局" else echo "計算機贏" fi ;; 3) if [ $num -eq 0 ] then echo "計算機贏" elif [ $num -eq 1 ] then echo "你贏" else echo "平局" fi ;; *) echo "請輸入1-3: " esac