Sponsored Content
Full Discussion: Menu in Menu script issue
Top Forums Shell Programming and Scripting Menu in Menu script issue Post 302475286 by ctsgnb on Saturday 27th of November 2010 06:35:22 PM
Old 11-27-2010
You can lop in ==Calculator Program==

just the same way you loop in ==Option menu==

You can use break to get out of a while loop without exiting the entire script.

Use function when you do some tasks many times.

By the way, here is a sample of your code with some little improvment
Code:
case $option in

1)
compute(){
        echo $1
        echo "Enter first number" ; read a
        echo "Enter second number"; read b
        op=`expr $a "$SIGN" $b`
        [[ $op -ge 0 ]] && COLOR=$BLUE || COLOR=$RED
        echo -e Answer is: $COLOR"$op"$BLACK
}

while :
do
        echo ==Calculator Program==
        echo "1 - Addition"
        echo "2 - Subtraction"
        echo "3 - Multiplication"
        echo "4 - Division"
        echo "5 - Back to previous Menu"
        echo "6 - Exit"
        echo "Please enter your option"
        read option

        MSG="" ; SIGN=''
        case $option in
                1) MSG="==Addition==" ; SIGN='+' ; compute "$MSG" ;;
                2) MSG="==Subtraction==" ; SIGN='-' ; compute "$MSG" ;;
                3) MSG="==Multiplication==" ; SIGN='*' ; compute "$MSG" ;;
                4) MSG="==Division==" ; SIGN='/' ; compute "$MSG" ;;
                5) clear ; break ;;
                6) echo "Ok bye" ; exit 0 ;;
                *) echo "Enter valid option" ;;
        esac
done
;;

If we want to exit, there already is a choice in the menu, so .... the following lines are useless (and even bad for the workflow of query)
Code:
echo "Do you want to contine (Y/N)"
read opt;
echo $opt | grep -i 'y'
if [[ $? -eq 0 ]]
then
 clear
else
 exit 0
fi


Last edited by ctsgnb; 11-27-2010 at 09:02 PM..
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Menu script

It's me again :) I would like to create a script that will display a 'Main Menu' which will link to other scripts in the same directory. Is it possible to have a scrolling menu and pretty colours for this? :) (9 Replies)
Discussion started by: Ypnos
9 Replies

2. Shell Programming and Scripting

Need help with script for menu

I'm working on a script for a basic menu with four options. The first option for the menu asks a user to put in anyone's user name and is supposed to display the user's home directory. If a user does not enter a name, then their own home directory should be displayed. The second menu option is... (0 Replies)
Discussion started by: sinjin
0 Replies

3. Shell Programming and Scripting

Menu Script

So, I need help writing a Menu script in UNIX. First how can I use letters for the options instead of numbers? Also, is there any templates out on the web I can use? (2 Replies)
Discussion started by: Gboy
2 Replies

4. Shell Programming and Scripting

Variable sub-menu issue

The code im having problems with is highlighted in red, upon selecting option 2 on the main menu (highlighted green) my echo "NETWORK CONNECTIVITY" command seems to get overlooked and the resulting output is "Thank you for using the Operator Administrative Tool." being displayed. Can anyone tell me... (2 Replies)
Discussion started by: warlock129
2 Replies

5. Shell Programming and Scripting

Menu using shell script

Hi, I need to have a shell script for the below need. 1. Menu with one heading and 4 options. 2. the heading and 4 options are taken from a file. File entry ====== Heading1|option1|option2|option3|option4| Heading2|option1|option2|option3|option4| 3. the user entries must be captured in... (9 Replies)
Discussion started by: umastinu
9 Replies

6. Shell Programming and Scripting

Menu with sub-menu options

Hi! I have created on script which is working fine with menu options and with a sub-menu. I want to enhance it by using sub-options under menu options. Like. option 1) will give the list only. option 1.1) should give the option to user to choose one file, whose content user wanna see. ... (3 Replies)
Discussion started by: sukhdip
3 Replies

7. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

8. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies
Menu::Item(3)						User Contributed Perl Documentation					     Menu::Item(3)

NAME
Tk::Menu::Item - Base class for Menu items SYNOPSIS
require Tk::Menu::Item; my $but = $menu->Button(...); $but->configure(...); my $what = $but->cget(); package Whatever; require Tk::Menu::Item; @ISA = qw(Tk::Menu::Item); sub PreInit { my ($class,$menu,$info) = @_; $info->{'-xxxxx'} = ... my $y = delete $info->{'-yyyy'}; } DESCRIPTION
Tk::Menu::Item is the base class from which Tk::Menu::Button, Tk::Menu::Cascade, Tk::Menu::Radiobutton and Tk::Menu::Checkbutton are derived. There is also a Tk::Menu::Separator. Constructors are declared so that $menu->Button(...) etc. do what you would expect. The "-label" option is pre-processed allowing ~ to be prefixed to the character to derive a "-underline" value. Thus $menu->Button(-label => 'Goto ~Home',...) is equivalent to $menu->Button(-label => 'Goto Home', -underline => 6, ...) The "Cascade" menu item creates a sub-menu and accepts these options: -menuitems A list of items for the sub-menu. Within this list (which is also accepted by Menu and Menubutton) the first two elements of each item should be the "constructor" name and the label: -menuitems => [ [Button => '~Quit', -command => [destroy => $mw]], [Checkbutton => '~Oil', -variable => $oil], ] -postcommand A callback to be invoked before posting the menu. -tearoff Specifies whether sub-menu can be torn-off or not. -menuvar Scalar reference that will be set to the newly-created sub-menu. The returned object is currently a blessed reference to an array of two items: the containing Menu and the 'label'. Methods "configure" and "cget" are mapped onto underlying "entryconfigure" and "entrycget". The main purpose of the OO interface is to allow derived item classes to be defined which pre-set the options used to create a more basic item. BUGS
This OO interface is very new. Using the label as the "key" is a problem for separaror items which don't have one. The alternative would be to use an index into the menu but that is a problem if items are deleted (or inserted other than at the end). There should probably be a PostInit entry point too, or a more widget like defered 'configure'. perl v5.12.1 2007-05-05 Menu::Item(3)
All times are GMT -4. The time now is 03:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy