I have menu option in my script and in that i have 4 options like below :-
echo "Please select a target server .."
echo "[1] AIX - AIX1"
echo "[2] AIX - AIX2"
echo "[3] AIX - AIX3"
echo "[4] HP-UX - HP-UX1"
echo "Enter your menu choice [1-11]: \n"
read tgtser
case $tgtser in
1|2|3|4)
echo "Checked out to test server ..." ;;
*)echo "Opps !!! please select a valid option" ;;
If i gave anything other than 1 to 4, it is exiting now. But I want the control to be moved to first so that it will show the menu option again instead of exiting from the script:b:...
#!/bin/bash
menu()
{
clear
echo "Please select a target server .."
echo "[1] AIX - AIX1"
echo "[2] AIX - AIX2"
echo "[3] AIX - AIX3"
echo "[4] HP-UX - HP-UX1"
echo "Enter your menu choice [1-11]:"
}
menu
while read tgtser; do
case $tgtser in
1|2|3|4)
echo "Checked out to test server ..."
break
;;
*)
echo "Opps !!! please select a valid option"
sleep 2
menu
;;
esac
done
exit 0
#!/bin/bash
tgtser=""
function menu
{
clear
echo "Please select a target server .."
echo "[1] AIX - AIX1"
echo "[2] AIX - AIX2"
echo "[3] AIX - AIX3"
echo "[4] HP-UX - HP-UX1"
echo "Enter your menu choice [1-11]: \n"
read tgtser
}
while true
do
menu
case $tgtser in
1|2|3|4)
echo "Checked out to test server ..."
break
;;
*)echo "Opps !!! please select a valid option"
sleep 2
menu
;;
esac
done
--ahamed
---------- Post updated at 04:20 AM ---------- Previous update was at 04:19 AM ----------
oh man!!... exactly (~99%) same code... even the sleep timer...
I will show the entire code and then probably you can help me ..
# Ver Date Description Analyst
# --- ---- ----------- -------
# A01 09/08/11 Original Implementation Renjesh Raju
#***************************************************************************
function menu
{
clear
echo "[1] check-out to test server"
echo "[2] check-in"
echo "[3] check-out to local machine"
echo "[4] Exit/stop"
echo "----------------------------------------------"
echo "Enter your menu choice [1-4]: \n"
read choice
case $choice in
1)
clear
echo "Please select a target server .."
echo "[1] AIX - AIX1"
echo "[2] AIX - AIX2"
echo "[3] AIX - AIX3"
echo "[4] HP-UX - HP-UX1"
echo "Enter your menu choice [1-4]: \n"
read tgtser
case $tgtser in
1|2|3|4|)
echo "Checked out to test server ..." ;;
*)echo "Opps !!! please select a valid option" goto ;;
(From here, i need to go to the sub menu again)
esac
;;
2) echo "Checked in ..." ;;
3) echo "Checked out to local machine ..." ;;
4) echo "Exiting ... " ;;
*) echo "Opps !!! please select a valid option (1/2/3/4)" ;;
(From here, i need to go to the first menu again)
esac
}
menu
#!/bin/bash
PS3="Enter your menu choice [1-11]: "
select choice in "AIX - AIX1" "AIX - AIX2" "AIX - AIX3" "HP-UX - HP-UX1"
do
# consider a debug:
echo $REPLY
echo $choice
if [ $REPLY -lt 5 ]
then
# your code including case statement goes here
break;
fi;
done
This only repeats the whole menu if you enter a blank line. Place the break in one of your options if you want it to repeat. The above solutions can be made more sophisticated than this but it is built into bash, ksh and zsh. And EOF (^-D) entered into the prompt finishes the loop too. What does it do with the above solutions? (don't tell me, I can try them for myself if I'm interested).