LinuxQuestions.org
Visit Jeremy's Blog.
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 10-07-2003, 06:15 PM   #1
ravvar
LQ Newbie
 
Registered: Oct 2003
Location: .au
Distribution: Debian, FreeBSD and RedHat
Posts: 11

Rep: Reputation: 0
Bash case structure (looping)


Hey, i'm really not sure what the best way is to 'loop' a case strcture back to the top, i've looked through many howto's but can't seem to find a method. This is what i'm on about. Example:

case $OPT in

"H"|"Help" )
echo "---- Help ----"
echo
echo "Next: jumps this section"
echo "Edit: edit's the chain"
;;

"N"|"Next" )
echo "skipping..."
;;

* )
What do i do here in order to make any other entry 'loop' back to the start of the case structure instead of ending, the only way i want this case structure to end is if the user inputs "N"/"Next". I could do it by containing the case structure within a function and calling that function in anything other than "Next", but that may get messy no? I'm reall not sure.

One more thing is: How can i pass input from a shell script into an interactive program, e.g passwd.
 
Old 10-07-2003, 06:29 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Sounds like you need while and break structure around the case. That is, having "while [[ 1]]" loop and calling break in the "N"|"Next") entry.

See
Adv Bash scripting guide for more details.
 
Old 10-07-2003, 06:42 PM   #3
ravvar
LQ Newbie
 
Registered: Oct 2003
Location: .au
Distribution: Debian, FreeBSD and RedHat
Posts: 11

Original Poster
Rep: Reputation: 0
mm, that's a good idea, should have thought of it myself! Thanks.
Any ideas on the input into an interactive program? :/
 
Old 10-07-2003, 06:59 PM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
You could pipe something to the program as an input (like echoing something or "cat"ing some files). If you need more fine-grained control over the input, you should apt-get install expect
 
Old 10-07-2003, 07:07 PM   #5
ravvar
LQ Newbie
 
Registered: Oct 2003
Location: .au
Distribution: Debian, FreeBSD and RedHat
Posts: 11

Original Poster
Rep: Reputation: 0
hey, nice one (expect). I don't think piping works with interactive programs, but expect may do the job. Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Converting sLoPPy cASE to Pretty Case with tr lowpro2k3 Programming 4 04-13-2005 08:13 PM
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
The case of the disappearing bash history geomatt Linux - General 5 03-02-2005 04:08 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 04:15 AM
[C] for looping problem wuck Programming 6 10-19-2003 04:29 PM


All times are GMT -5. The time now is 02:36 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration