【程式】(取自參考 #1)
#!/bin/bash PS3='Choose your favorite vegetable: ' select vegetable in "beans" "carrots" "potatoes" "onions" "rutabagas" do echo echo "Your favorite veggie is $vegetable." break # What happens if there is no 'break' here? done exit
【結果】
./s.sh 1) beans 2) carrots 3) potatoes 4) onions 5) rutabagas Choose your favorite vegetable: 6 Your favorite veggie is . root@ed-desktop:/tmp# ./s.sh 1) beans 2) carrots 3) potatoes 4) onions 5) rutabagas Choose your favorite vegetable: 1 Your favorite veggie is beans.
【參考】
- Creating menus using select
http://tldp.org/LDP/abs/html/testbranch.html#EX31