2010-11-14 41 views
3

我試圖得到這個工作:使用的選擇提供了語法錯誤

echo "Would you like to configure dns?" 
select yn in "Yes" "No"; do 
    case $yn in 
     Yes) echo "you have selected to configure dns"; break;; 
     No) exit; break;; 
    esac 
done 

我不斷收到此錯誤:提前

menu.sh: 2: select: not found
menu.sh: 7: Syntax error: "done" unexpected

感謝, 喬

回答

12

確保你正在運行它bashselectbash理解,而不是像sh一些殼。

+0

的感謝! thatts它是什麼... – jmituzas 2010-11-14 17:33:12

0

或者,只需使用while,readcase重寫。我認爲select並沒有增加太多。

+0

你能給我一個我如何能做到這一點的例子。謝謝 – jmituzas 2010-11-16 14:51:43

+0

想我想通了你的情況,謝謝。 – jmituzas 2010-11-16 18:49:06

0

這裏有一個很好的,我從這個論壇上寫下了幫助:)

 #!/bin/bash 

     while ["$yn" != "Yes" ]; do 

    echo "Choose your type of installation" 

    echo "1) Home Media Server" 

    echo "2) Home Communication Server" 

    echo "3) Enterprise Communication Server" 

    echo "4) Hosting Server" 

    echo "5) Individual Packages" 

    echo "6) exit" 

    read case; 



    #simple case bash structure 

    # note in this case $case is variable and does not have to 

    # be named case this is just an example 



    case $case in 

     1) echo "You have entered Home Media Server, is this correct? (Yes or No)" 

     read yn 

       echo "Running script for Home Media Server";; 



     2) echo "You have entered Home Communication Server, is this correct? (Yes or No)" 

     read yn 

       echo "Running script for Home Communication Server";; 



     3) echo "You have entered Enterprise Communication Server, is this correct? (Yes or No)" 

     read yn 

       echo "Running script for Enterprise Communication Server";; 



     4) echo "You have entered Hosting Server, is this correct? (Yes or No)" 

     read yn 

       echo "Running script for Hosting Server";; 



     5) echo "You have entered $hname, is this correct? (Yes or No)" 

     read yn 

       echo "Running script for Individual Packages";; 



     6) exit 

    esac