LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2011, 05:35 PM   #1
kasparov29
LQ Newbie
 
Registered: Oct 2011
Posts: 22

Rep: Reputation: Disabled
Question 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,
 
Old 12-02-2011, 09:34 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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.

Cheers,

Josh
 
Old 12-03-2011, 06:06 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 12-03-2011, 06:36 AM   #4
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by kasparov29 View Post
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,
Make a loop.

Pseudocode
Code:
while(lowercase(ask_user("would you like to continue")) == 'y'){
   do_something();
}
 
Old 12-05-2011, 12:21 PM   #5
kasparov29
LQ Newbie
 
Registered: Oct 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkisofs -iso-level 1 converts to lower case instead of upper case. stf92 Slackware 3 10-29-2010 12:32 AM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 07:03 PM
renaming directories from upper case to lower case, help!! linux_teller Linux - Newbie 3 03-07-2008 05:15 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM
system() function in nested if else/case! natalinasmpf Programming 10 01-26-2004 06:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration