使用select会出现语法错误

时间:2010-11-14 17:01:37

标签: bash select syntax syntax-error

我想让这个工作:

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:选择:未找到
  menu.sh:7:语法错误:“完成”意外

先谢谢, 乔

3 个答案:

答案 0 :(得分:12)

确保您在bash中运行它,因为select bash理解sh而不是{{1}}等一些shell。

答案 1 :(得分:0)

或者,只需使用whilereadcase重写即可。我认为select并没有真正增加太多。

答案 2 :(得分: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