Using select gives a syntax error

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" unexpectedly

Thanks Advance, Joe

+3
source share
3 answers

Make sure that you run it in bash, as selectunderstood bash, and not by some type shells sh.

+12
source

Alternatively, simply rewrite with while, readand case. I think that selectdoesn’t add a lot.

0
source

, :)

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

Source: https://habr.com/ru/post/1774804/


All Articles