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

How can I make this work so that if answer is incorrect go back to ask it again? I know I need a while loop to achieve this but don't know how to write it up.

2 Answers 2

3

This ought to do it:


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
Sign up to request clarification or add additional context in comments.

1 Comment

you get the points for this, thanks for the fast reply answered within 15 mins.
0

Here's another one you helped me out on writing:

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

Thanks once again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.