I'm trying to get a case statement to start over if an undefined option is selected... But I am ata loss on how to actually do it.
Here is a quick example of what I have.
Echo "1) do this/n
2) Do that/n
3) Quit/n
Make a selection/n"
Read answer
Case answer in
1) Dothid;;
2) Dothat;;
3) Exit;;
*) restart the echo menu
Can anyone point me in the correct direction on how to do this... Ithink that I need a while loop but I am not sure how to structurew it.
Please ignore the sloppy example and typos, stuck on a blackberry
here is an example using select. if you don't want to use select you can just write a loop around your existing code and "continue" if they don't select a valid option.
select f in foo bar blah
do
case "$f" in
foo) echo foo
break
;;
bar) echo bar
break
;;
blah) echo blah
break
;;
*) echo sorry
esac
done
trey85stang:
Echo "1) do this/n
2) Do that/n
3) Quit/n
Make a selection/n"
Read answer
Case answer in
1) Dothid;;
2) Dothat;;
3) Exit;;
*) restart the echo menu
Please ignore the sloppy example and typos, stuck on a blackberry
Are u goin to make selection as only 1,2 or 3 or is it full line..
Suppose that u have to make selection as 1) do this then do the following :
case $answer in
"1\) do this")
echo Dothis
;;
"2\) do that")
echo Dothat
;;
"3\) quit")
echo exit
;;
*) restart the echo menu
;;
esac
I dont have access to unix server right now sop dint try out my code. Please let me know whether it works.
frank, changing everything to select worked perfectly for my needs. Thank you very much!