select 类似与菜单功能

fruits=(
"apple"
"pear"
"orange"
)
echo "Please guess which fruit I like :"
select var in ${fruits[@]}
do
    if [ $var == "apple" ]; then
        echo "Congratulations, you are my good firend!"
        break
    else
        echo "Try again!"
    fi
done

运行:

Please guess which fruit I like :
1) apple
2) pear
3) orange
4) watermelon
#? 1   (我最白痴的地方,我一开始输出了apple,不是“1”,结果没输出,因此找“bug”好久)
====apple
Congratulations, you are my good firend!

相关文章:

  • 2021-09-26
  • 2022-02-13
  • 2022-12-23
  • 2021-07-06
  • 2021-09-09
  • 2021-07-04
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2021-10-22
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2021-07-12
  • 2022-01-17
  • 2022-12-23
相关资源
相似解决方案