轉載自:http://blog.sina.com.cn/s/blog_6151984a0100el04.html
select 表達式是一種bash的擴展應用,動作包括:
[macg@machome ~]$ vi test.sh echo "What is your favourite OS?" select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do break done echo "You have selected $var" |
[macg@machome ~]$ sh test.sh What is your favourite OS? 1) Linux 2) Gnu Hurd 3) Free BSD 4) Other #? 2 You have selected Gnu Hurd |
雖然select本身就是循環,但不建議用他的循環 ,因爲select雖然循環卻不再顯示菜單,只循環輸入,所以seleckt 語句乾脆直接用break,只執行一次,在其上另配while循環
while echo "display current netconfig:" do select vi in "ifconfig -a" "hosts" "netmasks" "quit" do case $vi in "ifconfig -a") "hosts") more hosts;; "netmasks") more netmasks;; "quit") return 0;; *) continue;; esac break done done |
$ sh test display current netconfig 1) ifconfig -a 2) hosts |