Question on returning back a level with menus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question on returning back a level with menus
# 1  
Old 08-18-2012
Question on returning back a level with menus

Hi Agian

Sorry for all these questions...:

Last one for a whie, I promise

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


Code:
#! /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,,,

Thanks again
# 2  
Old 08-18-2012
You can use a goto as you suggested. You could also wrap all of what you have inside something like:
Code:
while true
do      your current script (except add a break when you're ready to leave the loop)
done

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-18-2012
Hi Don

I know I am doing something pretty silly..but just cant find it Smilie

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

Code:
#! /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

# 4  
Old 08-18-2012
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:
Code:
activeWM=$(whiptail ...)
        exitstatus=$?
        echo "User selected Ok and entered $activeWM"
        if [ $exitstatus -eq 1 ]; then break; fi;

This User Gave Thanks to RudiC For This Post:
# 5  
Old 08-18-2012
Hi RudiC


Will try that later and see how it goes & give u a update... Appreciate all your help with this BTY

Regards
Dan
# 6  
Old 08-18-2012
Quote:
Originally Posted by RudiC
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:
Code:
activeWM=$(whiptail ...)
        exitstatus=$?
        echo "User selected Ok and entered $activeWM"
        if [ $exitstatus -eq 1 ]; then break; fi;

None of the systems I use have thewhiptailutility, so I can 't really test it out. But, I agree with RudiC that thedoneneeds to be moved after thefiat the end of the script.

Just by looking at the man page, I would guess that the:
Code:
if [ $exitstatus -eq 1 ]; then break; fi;

should be changed to:
Code:
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).
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 08-19-2012
@Don Cragun: Agreed. Good point. I did not test all options. Thanks!
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cascading bash menus

I currently have a main menu (using whiptail) and one of the options makes an instance of another menu - sort of cascading fashion. I like to be able to terminate the current (top) menu and return to the underlying main one. I was thinking enclosing the main menu in "do... done" block. ... (0 Replies)
Discussion started by: annacreek
0 Replies

2. Red Hat

SSL certificate generation on OS level or application level

We have a RHEL 5.8 server at the production level and we have a Java application on this server. I know of the SSL certificate generation at the OS (RHEL) level but it is implemented on the Java application by our development team using the Java keytool. My doubt is that is the SSL generation can... (3 Replies)
Discussion started by: RHCE
3 Replies

3. UNIX for Dummies Questions & Answers

General question about folder level permissions

How is the level of access on a particular folder determined? I have heard (its just hearsay so am not particularly sure of it) that the access a particular user/group has to a low level directory is also affected by the level of access granted to the user/group on its parent directories. e.g. ... (1 Reply)
Discussion started by: jawsnnn
1 Replies

4. AIX

rolling back Technology Level

Hi, is it possible to roll back currently updated Technology level ? what are steps required? Regards, Manoj (2 Replies)
Discussion started by: manoj.solaris
2 Replies

5. AIX

EEEK - OSLEVEL -r is now reverted back to original level

Dont know what happened, my AIX 53 TL6 os just reverted back to original TL4 from whence I started this week. Is there a commad to check the ODM or kernel or something to ensure stability? (2 Replies)
Discussion started by: mrmurdock
2 Replies

6. Shell Programming and Scripting

Expression recursion level question

Hi. I am receiving this error message for the highlighted line (let "total=$total+$sales"). line 11: let: total+sales:expression recursion level exceeded (error token is "total+sales") counter=0 sales=0 total=0 echo "enter sales price" read sales total=total+sales while test $sales ; do... (5 Replies)
Discussion started by: Ccccc
5 Replies

7. Solaris

Difference between run level & init level

what are the major Difference Between run level & init level (2 Replies)
Discussion started by: rajaramrnb
2 Replies

8. UNIX for Dummies Questions & Answers

? question mark, how to get back to the root directory

hiyas I am trying to get back to the root directory: I went into MAIL directory and now I can't get back to the root directory. What are the commands... I have '?' coming up and I cannot proceed with this, HELP Cheers (1 Reply)
Discussion started by: etravels
1 Replies

9. UNIX for Dummies Questions & Answers

enterprise level permissions question?

Can someone give me an example of Enterprise level permissions? (4 Replies)
Discussion started by: wmosley2
4 Replies

10. Programming

ncurses -> the best way to use menus

hello there, i'm exploring the curses lib and i'm having some trouble with "defining a style". to clarify: i'm creating a menu driven app and i've been thinking what's the best way to use menus: make global vars (not my favourite), creating a function which designs the menu and returns the... (2 Replies)
Discussion started by: crashnburn
2 Replies
Login or Register to Ask a Question