Quit Function Issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Quit Function Issues
# 1  
Old 04-25-2009
Quit Function Issues

Hi everyone,

I am writing a small menu driven program and have come across a problem i am having trouble solving. I am using Windows XP and i am developing this in the Unix Bash shell. I am trying to make it possible to exit the program from each of the five main interfaces. The code is as shown below:

Code:
#!/bin/bash
#Filename: Assigntest Author: Luke Francis
quit=n
while [ "$quit" = "n" ]
do
clear
echo "OPERATOR ADMINISTRATIVE TOOL"
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Q. Quit"
echo
echo "Which option do you require?"

read menunumber
case $menunumber in
1)clear
echo "USER INFORMATION"
 echo "1. Registered Users"
 echo "2. Disk Usage"
 echo "3. Last Logins"
 echo "4. Users Currently Logged In"
 echo "5. Total number of users"
 echo "Q. Quit"

echo "Which option do you require?"

read menunumber2
case $menunumber2 in

1)clear
echo "The users registered on the system are:"
echo
awk -F: '{print $1}' /etc/passwd
echo
echo "Hit the Enter Key to continue"
read junk;;

2)clear
echo "Disk Usage is as follows:"
echo
du
echo
echo "Hit Enter Key to continue"
read junk;;

3)clear
echo "Information on last noted login can be found next to each username."
echo
last
echo
echo "Hit Enter Key to continue"
read junk;;

4)clear
echo "Users currently logged in are:"
echo
 w
echo
echo "Hit Enter Key to continue"
read junk;;

5)clear
echo "The total number of users are:"
echo
 who -q
echo
echo "Hit Enter Key to continue"
read junk;;

Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice1
case $choice1 in
N|n)clear
echo "Hit Enter Key to continue"
read junk;;

Y|y)quit=y;;
*)clear
sleep 1
esac
esac
esac
done
clear
echo "Thank you for using the Operator Administrative Tool"


My quit command at the bottom (code after Q|q) ) works fine but i am trying to apply it to my main menu (after "OPERATOR ADMINISTRATIVE TOOL") where and how within my code shall i go about doing this?

I'd be really grateful for some help. thanks
# 2  
Old 04-25-2009
I reread your question and I think you are asking why you can't seem to quit from the main menu, etc. It appears that you never finished your case statements for all your options so you have to account for them. Using your method and continuing from Q|q)clear...

Code:
         Q|q)clear
           echo "Are you sure you want to quit? Y/N"
           read choice1
           case $choice1 in
              N|n)clear
                 echo "Hit Enter Key to continue"
                 read junk;;

              Y|y)quit=y;;
              *)clear
                sleep 1;;
           esac
         ;;
         esac
       ;;
        2)echo Option 2 here...
          sleep 2
          clear
         ;;
        3)echo Option 3 here...
          sleep 2
         ;;
        4)echo Option 4 here...
          sleep 2
         ;;
        5)echo Option 5 here...
          sleep 2
         ;;
        Q|q)echo "Quitting from main menu..."
          exit 0
          ;;
      esac
done
clear
echo "Thank you for using the Operator Administrative Tool"


Last edited by giannicello; 04-25-2009 at 05:36 PM..
# 3  
Old 04-25-2009
I will try the above solution, see how it works out then i will report back with results. thanks alot for your help
# 4  
Old 04-25-2009
Ok before i try this method i wanted to know as the resulting code for each of my main menu selections has been placed under the variable of 'menunumber' would i have to include this in my quit statement for example:


Code:
Q|q)clear
           echo "Are you sure you want to quit? Y/N"
           read choice1
           case $choice1 in
              N|n)clear
                 echo "Hit Enter Key to continue"
                 read junk;;

              Y|y)quit=y;;
              *)clear
                sleep 1;;
           esac
         ;;
         esac
       ;;
        2)case $menunumber in
          sleep 2
          clear
         ;;

# 5  
Old 04-25-2009
I just want say thanks for all the help, i have managed to solve the issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. OS X (Apple)

Are you sure you want to quit Safari?

Hmmm. I cannot figure out where to disable this warning message in Safari. Google says to disable something in Safari Tabs preferences but my Macs do not have that option in Mojave. Anyone know how to disable the following so when I quit Safari it simply quits without the "freeze the... (12 Replies)
Discussion started by: Neo
12 Replies

2. Shell Programming and Scripting

Function Issues

I am converting English letters/words/punctuation in leet speak. My current script works just fine, but when I call the functions it seem to be bypassing my second function altogether. I am new to shell scripting so excuse me if its an easy fix. Also, when using SED for whole word phrases like... (4 Replies)
Discussion started by: bri09
4 Replies

3. Shell Programming and Scripting

Need to quit out of for loop.

Hi, Here is my code to send read.txt to three servers. col="prd167.mybank.com prd168.mybank.com bsprd169.mybank.com" set -A look $col for IndixList in ${look}; do scp /tmp/read.txt admin@$IndixList:/tmp done This works and all the 3 servers gets the read.txt file. However,... (8 Replies)
Discussion started by: mohtashims
8 Replies

4. UNIX for Advanced & Expert Users

how to quit or exit from WMToggle

I want directly to move from WMToggle to bash, which command to type? Now I need to type 3 times, :q! etc. any help? its very annoying to time something 3 times continuously :( (1 Reply)
Discussion started by: c_lady
1 Replies

5. Shell Programming and Scripting

if no file then quit

I have a script that run several subscripts. I need to find out how to do two things. First I would like to check for a file and if that file is not there I want to quit the entire script without running the rest of the script which contain subscripts. If the file is there, I want it to continue... (1 Reply)
Discussion started by: libertyforall
1 Replies

6. Programming

performance issues of calling a function in if condition

Hi, I have written a program in C and have to test the return value of the functions. So the normal way of doin this wud b int rc rc=myfunction(input); if(rc=TRUE){ } else{ } But instead of doing this I have called the function in the if() condition. Does this have any... (2 Replies)
Discussion started by: sidmania
2 Replies

7. Shell Programming and Scripting

How to quit from a script?

hi all, I am facing problem in shell scripting while using exit command, when ever i run a file using . ./<filename>, when i run the sae script as sh <filename> the script does not close the windows. since my script has function calls i have to use . ./ <filename>. Could any one tell me... (8 Replies)
Discussion started by: caro
8 Replies

8. Shell Programming and Scripting

quit any time

how can i read input to quit any time, for instance "type q to quit" I have a script like this echo "The first choice" read firstChoice echo "The second choice" read secondChoice Looking for a code to quit any time by pressing q to quit any help would be appreciated thanks (5 Replies)
Discussion started by: Qwond
5 Replies

9. UNIX for Dummies Questions & Answers

how to quit from glance

hi, if i am in glance, how do i exit? thanks (2 Replies)
Discussion started by: yls177
2 Replies
Login or Register to Ask a Question