ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
Could you post your script so we can see what you did so far? By posting it for us, it will give us a better visual to work with, and we can gladly further assist from 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,
Make a loop.
Pseudocode
Code:
while(lowercase(ask_user("would you like to continue")) == 'y'){
do_something();
}
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.