【Shell】select


【程式】(取自參考 #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.

【參考】

 

Ed32. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com