1

I want the Menu to run once and then ask if the user wants it to run again, if they say yes it it continues to run until they say no. I saw some examples online but im not understanding how to implement it.

#Menu
echo "Menu"
echo "1. Display the message that indicates when the <script> command stared"
echo "2. Dispay the message that indicates when the <script> command terminated"
echo "3. game score"
read answer

if[[ $answer == 1 ]]; then
 echo""
elif[[ $answer == 2 ]]; then
 echo""
elif [[ $answer == 3]]; then
fi

echo "Do you want to repeat this routine?(Y/N)"
read yesno

1 Answer 1

3

Other approach:

#the action functions
do_script_start() {
    echo "this is a message - start"
}
do_script_term() {
    echo "this is a message - term"
}
do_score() {
    echo "this is a game score"
}

# main 
ans=(
"Display the message that indicates when the <script> command stared"
"Dispay the message that indicates when the <script> command terminated"
"game score"
"exit menu"
)
PS3="Select what you want>"
select answer in "${ans[@]}"
do
case "$REPLY" in
    1) do_script_start ;;
    2) do_script_term ;;
    3) do_score ;;
    4) break ;;
esac
done
echo "here..."
Sign up to request clarification or add additional context in comments.

4 Comments

By PS3="Select what you want" you refer to the bash internal variable PS3?
@GeorgeVasiliou yes, the PS3 is used as select prompt.
I wanted to run the menu first, then once they selected their choice(either 1, 2, or 3) and it executed, it would ask if it wanted to run the menu again. can that be done?
@G3Spin of course. it can be done. And in my answer you could find every needed piece...

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.