1847086 Members
5940 Online
110262 Solutions
New Discussion

Re: creating a menu

 
SOLVED
Go to solution
Norman_21
Honored Contributor

creating a menu

I've created a menu with different options, but I used the esac at the end of the script which force me to log off after taking an option. Could anyone please advise to change the script to take me back to the menu after executing an option from the menu.
here is an example:
i.e.)
echo " 1. who am I"
echo " who is login"
echo " enter your choice \c:"
read VAR
case $VAR in
1) whoami
;;
2) finger|pg
;;
* ) echo " you have not entered a valid option"
esac
echo "end of program
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
11 REPLIES 11
Christian Gebhardt
Honored Contributor

Re: creating a menu

Hi

simply create a while-loop that is always true:

while true
do

echo " 1. who am I"
echo " who is login"
echo " enter your choice \c:"
read VAR
case $VAR in
1) whoami
;;
2) finger|pg
;;
3) exit
;;
* ) echo " you have not entered a valid option"
esac

done


Chris
Christian Gebhardt
Honored Contributor

Re: creating a menu

Hi

simply create a while-loop which is always true:

while true
do

echo " 1. who am I"
echo " who is login"
echo " enter your choice \c:"
read VAR
case $VAR in
1) whoami
;;
2) finger|pg
;;
3) exit
;;
* ) echo " you have not entered a valid option"
esac

done


Chris
Christian Gebhardt
Honored Contributor

Re: creating a menu

Hi

simply create a while-loop which is always true:

while true
do

echo " 1. who am I"
echo " who is login"
echo " enter your choice \c:"
read VAR
case $VAR in
1) whoami
;;
2) finger|pg
;;
3) exit
;;
* ) echo " you have not entered a valid option"
esac

done


Chris
Donald Kok
Respected Contributor

Re: creating a menu

Hi,
you can put a until-do-done construction around it like:

VAR=0
until (( VAR = 3 ))
do
case
add an option 3 exit ;;
done

Good luck
Donald
My systems are 100% Murphy Compliant. Guaranteed!!!
Donald Kok
Respected Contributor
Solution

Re: creating a menu

Hi,
you can put a until-do-done construction around it like:

VAR=0
until (( VAR = 3 ))
do
case
add an option 3 exit ;;
done

Good luck
Donald
My systems are 100% Murphy Compliant. Guaranteed!!!
Christian Gebhardt
Honored Contributor

Re: creating a menu

Hi

simply create a while-loop which is always true:

while true
do

echo " 1. who am I"
echo " who is login"
echo " enter your choice \c:"
read VAR
case $VAR in
1) whoami
;;
2) finger|pg
;;
3) exit
;;
* ) echo " you have not entered a valid option"
esac

done


Chris
Christian Gebhardt
Honored Contributor

Re: creating a menu

excuse me, my browser returned with error code 404 some times so I posted the answer again and agaian, ... but obviously the the forum works

Chris
Yogeeraj_1
Honored Contributor

Re: creating a menu

hi,

you already have the solution in the above replies.

to add on to them, a piece of code that i frquently use:
=============================
ANSW="X"
until [ $ANSW = "Y" -o $ANSW = "N" -o $ANSW = "y" -o $ANSW = "n" ] 2> /dev/null
do
echo "Do you want to continue?\c "
read ANSW
ANSW=${ANSW:-n}
done
=============================

Hope this helps too!

Best Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Norman_21
Honored Contributor

Re: creating a menu

Chris, Donald,
Thanks guys for the quick support.

Yojeeraj,

My man Yojeeraj, do I add it right under each option!
appreciate your advise.
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
James R. Ferguson
Acclaimed Contributor

Re: creating a menu

Hi:

Instead of checking input from a 'read' for uppercase and lowercase strings, declare the receiving variable of the read like this:

# typeset -l VAR

Now uppercase letters are converted to lowercase ones and you only need test for the lowercase variant.

Conversely, if you wsnt to convert all lowercase characters to uppercase characters, use:

# typeset -u VAR

Regards!

...JRF...
Norman_21
Honored Contributor

Re: creating a menu

Closed...
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003