Variable sub-menu issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable sub-menu issue
# 1  
Old 04-10-2009
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 how i can correct this, i want option 2 to bring up another sub-menu but for some reason it is not working even though it has been placed in the same menunumber variable.

#!/bin/bash
#Filename: Assignment Author: Luke Francis
clear
echo "OPERATOR ADMINISTRATIVE TOOL"
echo "Please enter your password:"
read password
if [ $password -eq 0600519 ]
then
clear
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Which option do you require?"

read menunumber
if [ $menunumber -eq 1 ]
then
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 "Which option do you require?"
read menunumber2
if [ $menunumber2 -eq 1 ]
then
clear
echo "The Users registered are:"
awk -F: '{print $1}' /etc/passwd
elif [ $menunumber2 -eq 2 ]
then
clear
du
elif [ $menunumber2 -eq 3 ]
then
clear
last
elif [ $menunumber2 -eq 4 ]
then
clear
w
elif [ $menunumber2 -eq 5 ]
then
clear
who -q
read menunumber
if [ $menunumber -eq 2 ]
then
clear
echo "NETWORK CONNECTIVITY"

fi
fi
fi
else
clear
echo "INCORRECT PASSWORD"
fi
echo "Thank you for using the Operator Administrative Tool."
# 2  
Old 04-10-2009
This is really hard to read without code tags and indentation, but I'd suggest you use case statements instead of a whole bunch of nested if statements -most likely the source of your problem is bad "if" nests.

I'd go for something like this:

Code:
case ${menunumber} in
        1) do something;;
        2) do something else;;
        3) show this menu
            case ${menunumber2} in
                    1) do this;;
                    2) do that;;
            esac
         *) not a choice;;
esac

# 3  
Old 04-10-2009
I'd suggest using ksh's "select" to built menus - it's much easier to manage.
A sample:
Code:
#!//bin/ksh

files='*sh';
actions='cat edit quit'
PS3="Pick one of the above [${actions}]: "
TMOUT=10

select i in ${actions}
do
   case $i in
      cat)  eval cat "${files}" ;;
      edit) eval ${EDITOR-vi} "${files}" ;;
      quit) break ;;
      "") print -u2 you must select one of the above [${actions}] ;;
   esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

3. 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

4. Shell Programming and Scripting

Whiptail menu, getting back the variable

Hi all Only learning so if any mistakes, let me know I am trying to create a menu box with Whiptail, taking in the variables from a txt.file called Name.txt which has just 4 names listed for now, one below each other..ie Dave John Mike Mary Bash script is below and calls the txt... (8 Replies)
Discussion started by: olearydc
8 Replies

5. Shell Programming and Scripting

variable issue

Hi, I'm sure that it's a very simple issue. this is a part of my code : while read ligne do result=`ls -R ../FILES/|grep "."$ligne"$"` echo $result done<TYPE_EXT_FILES.txt the echo return nothing (as my variable is empty). I'm sure that the problem... (10 Replies)
Discussion started by: skubann
10 Replies

6. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

7. UNIX for Dummies Questions & Answers

Input A Menu Selection In A Variable

hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked... #!/bin/bash # A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX: error_0="Correct amount of... (1 Reply)
Discussion started by: SoVi3t
1 Replies

8. UNIX for Dummies Questions & Answers

How Do I Create A Multi Line Menu Variable?

I want something that would show up basically like: Menu ----- 1) Option 1 2) Option 2 3) Option 3 Pick one: I tried menu = " Menu \r\n ----- \r\n 1)Option 1 \r\n..............etc etc etc" but that didnt work (just got the whole menu one one line, with the... (2 Replies)
Discussion started by: SoVi3t
2 Replies

9. UNIX for Dummies Questions & Answers

Using a list menu as a variable

Hi again I have the follwing - cat ~/ABCFILE | grep "$SYSTEM" | grep "$USERNAME" What I'm looking to do is have the variable for $SYSTEM determined by the user making a selection from a numbered list. So, input 1 would be system ABC etc. I'm very puzzled as to how to go about this? Any... (3 Replies)
Discussion started by: Great Uncle Kip
3 Replies
Login or Register to Ask a Question