Sponsored Content
Full Discussion: Switch Case not working
Top Forums Shell Programming and Scripting Switch Case not working Post 302614749 by Rapcher on Wednesday 28th of March 2012 07:45:44 PM
Old 03-28-2012
Switch Case not working

My switch case is not working properly. When I press 6 or 'r' it prints out all the names of the project and the error message.

Code:
#!/bin/bash

while true; do

    read -p "Enter project number (1/2/3/10/20/30):" menu
    #grabs the informations of the project number and stores it into a menu
    case "${menu}" in
          1)  awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
                ;;
          2)  awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
               ;;
          3)  awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
               ;;
          10) awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
               ;;
          20) awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
               ;;
          30) awk -F ":"  '/'$menu:'/ {print "Project Name: ", $1}' project.txt
               ;;
          *)  echo "No project exists with the given project number: ${menu}"
               ;;
    esac
    
    var2=$(awk -F ":" '/'$menu:'/ {print $4}' project.txt)
    
    var3=$(awk -F ":" '/':$var2:'/ {print $3}' department.txt)
    
    cut -d ":" -f 1-4 employee.txt > temp.txt

awk -F ":" '/'$var3'/ {print "Managers Name: ", $1,$2,$3}' temp.txt
/bin/rm temp.txt

    awk -F ":" -v MEN=$menu '$2==MEN { hours += $3; } END { printf "Total Employee Hours: %.2f\n", hours }' works_on.txt

    awk -F ":" -v ID=$var3 '$1==ID { count ++ } END { printf "Total number of dependents: " count "\n"}' dependent.txt

    read -p "Would you like to process another project? [y/n]" yn
    case $yn in
        [Yy]* ) ;;
        [Nn]* ) exit;;
        *) echo "Please select proper entry:";;
    esac
done

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ignore case sensitive in Case Switch

In a Case switch, how to ignore case sensitive in the test: e.g. case "$field" in "TEST) action1;; *) action2;; esac How to go in action1 in case of $field = TEST , or Test , or test or .... without enumerating all possibilities... Thanks,... (1 Reply)
Discussion started by: annelisa
1 Replies

2. UNIX for Dummies Questions & Answers

grep -A switch not working correctly with -m

egrep -A 7 -m 2 -h 'Date:|Time:' *.html this is showing only 2 line after the context of the 2nd found match. Is this a bug in grep? egrep -A 7 -m 2 -h 'Time:' *.html - this works correctly (2 Replies)
Discussion started by: zer0
2 Replies

3. Shell Programming and Scripting

Help needed in switch case handling in UNIX

Hi, In below code, i am expecting the output has Bye Bye But i am getting has Bye Hi Code: #!/usr/bin/bash var="Hi" cat txt.txt | while read var1 do next="Bye" case $var in Hi) (1 Reply)
Discussion started by: Balamani
1 Replies

4. Shell Programming and Scripting

Help needed in Switch Case

Hi Experts team, i wish to use switch case in unix. my req is case $code in 1111) echo "1111" 1112) echo "1112" *) echo "default" esac see eventhough for particular case 1111 , it is always execute the default statement *), if i code like this. How can handle... (2 Replies)
Discussion started by: spkandy
2 Replies

5. Shell Programming and Scripting

Example of switch case in Bash

can anyone post a sample code for a switch case in shell (1 Reply)
Discussion started by: sumit the cool
1 Replies

6. Shell Programming and Scripting

Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code: while : do ... (2 Replies)
Discussion started by: snakemasterAK
2 Replies

7. Shell Programming and Scripting

Error while executing switch case for find and replace specific file. Help Me...

case "$inputs" in sapte) find /pools/home_unix/sapte/work/models/model -name "*.xml" exec rm -i {} \;; ckm1) find /pools/home_unix/ckm1/work/models/model -name "*.xml" exec rm -i {} \;; I am getting error like as below. ./menu1.sh: line 144: syntax error near unexpected token `)'... (4 Replies)
Discussion started by: lathigara
4 Replies

8. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

9. Shell Programming and Scripting

Why does it not work (Switch Case)?

Hi there, I'm trying to run a simple script,but i'm always getting this error Syntax error: word unexpected (expecting "in")I have searched many sites,like this,but i dont get it,it looks good so far,but wont work,maybe someone can help me. Here is the Script #!/bin/bash while : do... (6 Replies)
Discussion started by: JustAnUser
6 Replies
install-menu(1) 					      Debian GNU/Linux manual						   install-menu(1)

NAME
install-menu - Process a menu method and generate the menu files for a window manager or a menu-aware application. DESCRIPTION
update-menus(1) computes the list of menu entries and passes it in turn to the menu methods in /etc/menu-methods/. The task of a menu meth- ods is to generate menus for a specific window manager. install-menu provides a generic and customizable way to do that. The documentation of the install-menu definition language is available in the Debian Menu manual, a local copy being available in /usr/share/doc/menu/html. SYNOPSIS
install-menu [-vh] [--remove] <menu-method> Read menu entries from stdin in update-menus --stdout format and generate menu files using the specified menu-method. Normally used in menu method scripts as #! /usr/bin/install-menu. OPTIONS
-h,--help Show the help message and exit. --remove Remove the menu files instead of generating them. -v,--verbose Output messages about what the program is doing. COPYING
install-menu is distributed under the term of the GNU General Public License version 2, or (at your option) any later version. AUTHOR
Written by Joost Witteveen <joostje@debian.org>. Now maintained by Bill Allombert <ballombe@debian.org>. SEE ALSO
update-menus(1), menufile(5), /usr/share/doc/menu/html Debian Project 28 November 2005 install-menu(1)
All times are GMT -4. The time now is 12:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy