Use of select gives syntax error

我只是一个虾纸丫 提交于 2019-12-20 02:28:32

问题


I am trying to get this to work:

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

I keep getting this error:

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

Thanks in Advance, joe


回答1:


Make sure you are running it in bash as select is understood by bash and not by some shells like sh.




回答2:


Alternatively, just rewrite using while, read and case. I think select does not really add much.




回答3:


Here's a good one I wrote up with the help from this Forum :)

     #!/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 


来源:https://stackoverflow.com/questions/4178565/use-of-select-gives-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!