#!/bin/bash # 猜数字游戏 size=6 echo "#####################" echo "## 猜数字游戏 ##" echo "## 1-"$size"之间 ##" echo "#####################" for i in `seq 1 $(($size-1))` do read -p "请输入你猜的数字: " number echo "欧,猜错了,还有"$(($size-$i-1))"次机会" array_number[$((i-1))]=$number done # 输出正确答案 for i in `seq 1 $size` do for number in ${array_number[@]} do if [ $i -eq $number ];then continue 2 fi done echo "正确答案是: "$i break done