This is an example of a menu script I am using. It works OK...when I get to the 2nd menu level, if the command is issued or canceled, I would like to go back to the first menu (# MAIN SECTION)
This is NOT the menu I have created..its a bit large so I have created a smaller version below to make things easier...ish
#! /bin/bash
# MAIN SECTION
activeWM=$(whiptail --backtitle "Hi" --title "PRESS YES OR NO " --radiolist "PRESS YES OR NO " 30 60 20 "ON" "PRESS YES OFF" ON "OFF" "PRESS NO" OFF 3>&1 1>&2 2>&3)
echo "User selected Ok and entered $activeWM"
OPTION='ON'
if [ "$OPTION" == "$activeWM" ];
then
echo "You pressed ON('$activeWM')"
whiptail --title "You pressed ON" --yesno "This is an example of a yes/no box." 8 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Yes."
else
echo "User selected No."
fi
echo "(Exit status was $exitstatus)"
else
echo "You Pressed OFF('$activeWM')"
whiptail --title "You pressed OFF" --yesno "This is an example of a yes/no box." 8 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Yes."
else
echo "User selected No."
fi
echo "(Exit status was $exitstatus)"
fi
Something like a goto back to the main section..and only then can someone cancel from the top menu,,,
I know I am doing something pretty silly..but just cant find it
I added the loop in and have done it in a few places but it just loops everything..and I normally just kill it and modify if possible
I am trying to go to the
First menu and when pressing OK, where it brings up one of 2 other menus depending on user selection
and once there if I press OK to do something or cancel...I was hoping it would to revert back to the first one again so that the user can select another option ..And ONLY when I do a cancel in the first menu, the script stops...
Its hard to explain but will work with the loop a bit and hope I can get it in the right place
Thanks again
#! /bin/bash
# MAIN SECTION
while true
do
activeWM=$(whiptail --backtitle "Hi" --title "PRESS YES OR NO " --radiolist "PRESS YES OR NO " 30 60 20 "ON" "PRESS YES OFF" ON "OFF" "PRESS NO" OFF 3>&1 1>&2 2>&3)
echo "User selected Ok and entered $activeWM"
# 2nd Menus
OPTION='ON'
if [ "$OPTION" == "$activeWM" ];
then
echo "You pressed ON('$activeWM')"
whiptail --title "You pressed ON" --yesno "This is an example of a yes/no box." 8 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Yes."
else
echo "User selected No."
fi
else
echo "You Pressed OFF('$activeWM')"
whiptail --title "You pressed OFF" --yesno "This is an example of a yes/no box." 8 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Yes."
else
echo "User selected No."
fi
done
fi
Looks like you have to reverse the order of done and fi at the end of the script to make it run correctly. If you want to leave the script with <cancel>, capture the exitstatus of the first whiptail cmd and evaluate:
activeWM=$(whiptail ...)
exitstatus=$?
echo "User selected Ok and entered $activeWM"
if [ $exitstatus -eq 1 ]; then break; fi;
None of the systems I use have the whiptail utility, so I can 't really test it out. But, I agree with RudiC that the done needs to be moved after the fi at the end of the script.
Just by looking at the man page, I would guess that the:
if [ $exitstatus -eq 1 ]; then break; fi;
should be changed to:
if [ $exitstatus -ne 0 ]; then break; fi;
so the user can get out of the loop if the user got out of whipcode by hitting the ESC key and if whipcode detects an error (exit code -1), as well as by the user selecting a NO or CANCEL button (exit code 1).