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. |
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. |
mm, that's a good idea, should have thought of it myself! Thanks.
Any ideas on the input into an interactive program? :/ |
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
|
hey, nice one (expect). I don't think piping works with interactive programs, but expect may do the job. Thanks
|
All times are GMT -5. The time now is 06:53 AM. |