Find the answer to your Linux question:
Results 1 to 4 of 4
Hi there, I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my ...
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17

    Nested case

    Hi there,

    I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my code start from beginning. I would like to continue my inner case until user press n or N. Is any one tell me how can I do?

    Thanking You,

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Can you post some code?

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    Hi,



    I am very sorry to delay reply. Please find my code as follow:



    Code:
    #!/usr/bin/sh
    
    wantMore ()
    
    {
    
    echo "Do you want to do more? "
    
    echo "Enter either "y or Y" to continue or "n or N" to exit."
    
    read key
    
    case "$key" in
    
    
    [yY]) continue
    
    ;;
    
    [nN]) exit ;;
    
    esac 
    
    }
    
    
    while true
    
    do
    
    clear
    
    echo "**************************************************** 
    
    * Main Menu *
    
    **************************************************** 
    
    1. aaaaaaaaaa 
    
    2. bbbbbbbbbbb
    
    3. ccccccccccccc 
    
    4. ddddddddd 
    
    5. Quit. 
    
    *****************************************************"
    
    echo "Enter your choice: "
    
    read choice
    
    
    case "$choice" in 
    
    1) some code
    
    wantMore
    
    ;; 
    
    
    2) some code 
    
    wantMore
    
    ;;
    
    3) 
    
    clear
    
    echo "**************************************************** 
    
    * Modify Menu *
    
    **************************************************** 
    
    a. aaaaaaaaaaa.
    
    b. bbbbbbbb
    
    c. ccccccccc
    
    d. dddddddddd
    
    e. eeeeeeeeee
    
    *****************************************************"
    
    echo "Enter your selection: "
    
    read option
    
    case "$option" in
    
    [aA]) some code
    
    wantMore
    
    ;;
    
    [bB]) some code
    
    wantMore
    
    ;;
    
    [cC]) some code
    
    wantMore
    
    ;;
    
    [dD]) some code
    
    wantMore
    
    ;;
    
    [eE]) some code
    
    wantMore
    
    ;;
    
    esac
    
    ;;
    
    4) some code
    
    wantMore ;; 
    
    5) echo "Good Bye!!!" 
    
    exit ;;
    
    
    *) echo Please enter valid option.
    
    sleep 2 
    
    continue 1;;
    
    esac
    
    done


    I would like to remian in appropriate case until user say n/N.

  4. #4
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    After looking at the code, I don't understand what you want. Give a specific example of what a user might select and what you want the code to do, i.e.,

    the user will choose 1) from the Main Menu and after arbitrary code is executed, they should be prompted to continue, and if yes, do this/show this menu, and if no, do that/show that menu, etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...