2010-11-14 101 views
0
#!/bin/bash 
echo "Please enter your Host Name" 
read hname 
echo "You have entered $hname, is this correct?" 
select yn in "Yes" "No"; do 
    case $yn in 
     Yes) sh runscript.sh; break;; 
     No) ; 
    esac 
done 

我该如何使这项工作,以便如果答案不正确回去再问一次? 我知道我需要一个while循环来实现这一点,但不知道如何写出来。bash而?循环选择菜单

回答

2

这应该做到这一点:


while [ "$yn" != "Yes" ]; do 
echo "Please enter your Host Name" 
read hname 
echo "You have entered $hname, is this correct? (Yes or No)" 
    read yn 
done 
sh runscript.sh 
+0

已测试,它的工作原理 – 2010-11-14 23:25:11

+0

你可以得到这个点数,感谢15分钟内回复的快速答复。 – jmituzas 2010-11-14 23:30:37

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 

再次感谢。