Tomb_Raider_Legend
Tomb_Raider_Legend

Reputation: 451

How to I return back to the main menu, from a function?

I have a problem coming back to the main menu, from a function. My BASH script looks something like this

 function functionA(){

    while [ "$choice" != x ]; do 
       echo "Press a to take action, and press b to exit and go back to the main list" 
       read choice 
       case $choice in 
          a)
             echo "Now lets do some stuff" 
             read 
             ... 
             ..... 
             ;; 
        x) 
           exit
       esac 
    done 
 }


 while [ "$choice" != x ];do 
     echo "Main list" 
     echo "Press a to go to functionA, press b to go to functionB, and press x to exit the program" 
     read choice

    case $choice in  
        a) functionA 
           ;; 
        b) functionB 
           ;;
       c) exit

    esac 
 done

So basically, if the user is in functionA() and presses x to quit, I want him to come back to the main list, and there he will be able to go to functionA() again or functionB(), or just press x again to quit the whole program.

Upvotes: 0

Views: 3707

Answers (1)

P.P
P.P

Reputation: 121357

When you input x in function(), you are calling exit in functionA() which makes whole script exit. Instead just return.

Upvotes: 3

Related Questions