Variable Selection Operation Error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable Selection Operation Error
# 1  
Old 04-26-2009
Variable Selection Operation Error

Ok i have taken your advised indented my code and i have managed to fix my problem but unfortuantely now another small one has arisen.

The problem is that executing my commands requires two presses of the ENTER key as opposed to the originally being pressed once as one would expect, for example when quitting the program you are asked "Are you sure you want to quit?" after pressing Y you then have to press enter twice before the program is closed whereas before i was once you would expect. My edited code has been included below:

Code:
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
;;
        Q|q)clear
          echo "Are you sure you want to quit? Y/N"
read choice2
case $choice2 in
        N|n)clear
            echo "Hit Enter key to continue"
                read junk;;

        Y|y)quit=y;;
        *)clear
           sleep 2;;
                esac
             ;;
                esac

read menunumber3
case $menunumber3 in

        2)clear
          echo "NETWORK CONNECTIVITY"
          echo
          echo "1. NIC Status"
          echo "2. Machine Availability"
          echo
          echo "Which option do you require?"

read menunumber4
case $menunumber4 in
1)clear
          echo "Information reagrding NIC status can be found below:"
          echo
          /sbin/ifconfig
          echo
          echo "Hit the Enter Key to continue"
          read junk;;

        2) clear
           echo "Available hosts and addresses are shown below:"
           echo
           cat /etc/hosts
           echo
           echo "Hit Enter Key to continue"
           read junk;;
        esac
       esac
done
clear
echo "Thank you for using the Operator Administrative Tool"

I hope you can understand what i am trying to get across, if not just say so i can explain. Also if possible could you please add any ammendmants recommended into the code i have supplied so i know exactly where to place them. Thanks alot for your help.
# 2  
Old 04-26-2009
Don't double post questions, please read the rules.

Proceed here:

https://www.unix.com/shell-programmin...ror-issue.html

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arithmetic operation in variable

Hi, Here is the script i try to perform arithmetic operation in two variables . git branch -r | while read brname ; do REV_COMMITS=`git rev-list --count $brname` echo "$brname has $REV_COMMITS" (( TOTAL = TOTAL + REV_COMMITS )) echo "in loop" $TOTAL done echo "total is " $TOTAL ... (3 Replies)
Discussion started by: greet_sed
3 Replies

2. Shell Programming and Scripting

Php assign selection to a variable

can someone help me assign the selection of a drop down menu to a variable? the variable i need to store the selection in is inputA. <form name="inputA"> <p align="center"> <p align="center">Name: <input name="inputA" type="text" size="45"> <select> <?php if ($handle =... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Variable%pattern operation within awk

Hello; I have: ll | grep -v ^d | awk '{print $9}' rcx_access_report_fid.txt rcx_access_report_hsi.txt rcx_access_report_mmm.txt rcx_access_report_qsc.txt I want to get: rcx_access_report_fid.txt rcx_access_report_hsi rcx_access_report_mmm rcx_access_report_qsc But when I try: (9 Replies)
Discussion started by: delphys
9 Replies

4. Shell Programming and Scripting

how to Declare 5 values to one variable with OR operation

what I'm trying to do is ... need to drop tables w/ names like ABC_NY_2001 ABC_ORD_2001 ABC_TX_2001 ABC_CL_2001 For this, I want to write a query "DROP TABLE ABC_var_2001". now "var" should be either NY, ORD, TX or CL. I'm new to programming so don't know how to create a variable w/ OR... (3 Replies)
Discussion started by: ramsowji
3 Replies

5. Shell Programming and Scripting

populate a bash variable from an awk operation

Hi, I'm trying to populate bash script variable, data_size with the size of the largest file in my current directory data_size=$(ls -lS | grep -v "total" | head -1) | awk '{ print $5 }' I've tried adding an echo before the call to awk data_size=$(ls -l | grep -v "total" | head -1) |... (2 Replies)
Discussion started by: mark_s_g
2 Replies

6. Shell Programming and Scripting

Arithmetic operation between columns using loop variable

Hi I have a file with 3 columns. say, infile: 1 50 68 34 3 23 23 4 56 ------- ------- I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561)) I am doing like this: for ((i=1; i<=3; i++)) do a=`echo... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies

7. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

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

9. Shell Programming and Scripting

piping ls to zenity and returning selection to variable

Hi I'm fairly new to unix and scripting (in BASH) and am here to post my first question. What I'm trying to do is pipe a sorted listing (ls) to zenity and when the list appears to the user, the choice they choose is returned to a variable so it can be used in conditional statements. I can... (2 Replies)
Discussion started by: Vayshan
2 Replies

10. Shell Programming and Scripting

KSH - Selection Sort Error

I have 'translated' selection sort from java to KSH, here is my code #1. get the inputs and put into arr print "Enter the integers (separated by a space):" read integers set -A arr $integers #2. start sorting process, using selection sort min=0 tmp=0 i=0 while test $i -lt... (2 Replies)
Discussion started by: laduch
2 Replies
Login or Register to Ask a Question