ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## select 结构 select结构主要用来生成简单的菜单 语法 ``` select name [in list] do commands done ``` ## 示例1 ``` #!/bin/bash PS3='Choose your favorite food: ' foods=("Pizza" "Pho" "Tacos" "Quit") select fav in "${foods[@]}"; do case $fav in "Pizza") echo "Americans eat roughly 100 acres of $fav each day!" break ;; "Pho") echo "$fav is a Vietnamese soup that is commonly mispronounced like go, instead of duh." break ;; "Tacos") echo "According to NationalTacoDay.com, Americans are eating 4.5 billion $fav each year." break ;; "Quit") echo "User requested exit" exit ;; *) echo "invalid option $REPLY";; esac done ``` 执行 ``` > bash a.sh 1) Pizza 2) Pho 3) Tacos 4) Quit Choose your favorite food: 1 Americans eat roughly 100 acres of Pizza each day! ```