multiple looping with case and funtion showing error, Please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple looping with case and funtion showing error, Please help
# 1  
Old 09-19-2011
MySQL multiple looping with case and funtion showing error, Please help

Hello All,

I have code as follows :-
Code:
while true do
  [calling a function]
   {opening a case1 statement} 
    1) 
      [Calling another function]
        {opening another case2 statement} 
        {closing case 2}
     2)
  Showing error for "2)" as Syntax error at line 59 : `)' is not expected.
     *) 
    {closing case 1} 
 done

This is the structure of my script. I am not able to figure out it. Could anyone crack this ?

Thanks
Renjesh
# 2  
Old 09-19-2011
If you expect people help you to troubbleshoot your script, then people need you to provide the code (and not only the structure of it).
# 3  
Old 09-19-2011
Here is the code :-
Code:
choice=""
tgtser=""
function menu
{
    clear
    echo "-------------------------------------------------------"
    echo " * * * * * * * Subversion Main Menu * * * * * * * * * * "
    echo "-------------------------------------------------------"
    echo "[1] check-out to test server"
    echo "[2] check-in"
    echo "[3] check-out to local machine"
    echo "[4] Exit/stop"
    echo "----------------------------------------------"
    echo "Enter your menu choice [1-4]: \n"
    read choice
}
function chkout1
{
     clear
     echo "Please select a target server .."
     echo "[1] AIX - st95esra"
     echo "[2] AIX - st95esrb"
     echo "[3] AIX - st95esre"
     echo "[4] HP-UX - st95esr0"
     echo "[5] HP-UX - st95esr1"
     echo "[6] HP-UX - st95esr2"
     echo "[7] Linux - st95esrn"
     echo "[8] Linux - st95esro"
     echo "[9] Linux - st95esrp"
     echo "[10] Linux - st95esrq"
     echo "[11] Linux - st95esrr"
     echo "Enter your menu choice [1-11]: \n"
     read tgtser
}
echo "================ MAIN SESSION =================="
while true do
     menu
     case $choice in
     1)
            chkout1
            case $tgtser in
                 1|2|3|4|5|6|7|8|9|10|11)
                         echo "Checked out to test server ..."
                         ;;
                 *)      echo "Opps !!! please select a valid option"
                         sleep 2
                         chkout1
                         ;;
            esac
     2)            echo "Checked in ..." ;;
            ;;
     3)
            echo "Checked out to local machine ..."
            ;;
     4)
            echo "Exiting ... "
            ;;
     *)
            echo "Opps !!! please select a valid option (1/2/3/4)" ;;
            sleep 2
            menu
            ;;
     esac
 done

Error showing in RED in the code :- ./test1[46]: Syntax error at line 60 : `)' is not expected.

Last edited by Scott; 09-19-2011 at 07:32 AM.. Reason: Code tags
# 4  
Old 09-19-2011
You miss ";;" after the "esac" which is just above the "2)"

Last edited by ctsgnb; 09-19-2011 at 09:42 AM..
# 5  
Old 09-19-2011
what happened ?
# 6  
Old 09-19-2011
I didn't try it so maybe it would require some fix, but in the main loop maybe it could be better with something like :
Code:
while true 
do
    menu
    case $choice in
    1)            
        while :
        do
            chkout1
            case $tgtser in
            1|2|3|4|5|6|7|8|9|10|11)
                echo "Checked out to test server ..."
                break
            ;;
            *)      echo "Opps !!! please select a valid option"
                sleep 2
            ;;
            esac
        done
    ;;
    2)
        echo "Checked in ..."
    ;;
    3)
        echo "Checked out to local machine ..."
    ;;
    4)
        echo "Exiting ... "
    ;;
    *)
        echo "Opps !!! please select a valid option (1/2/3/4)" ;;
        sleep 2
    ;;
esac
done

You must not make duplicate calls of 'chkout1' or 'menu' you must use the while loop instead.

Last edited by ctsgnb; 09-19-2011 at 09:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Looping through multiple arrays in C.

Not sure if this is possible, but I've tried this about a thousand ways now. I am making something with a lot of arrays. I thought I could put the array names into a separate array and then loop through them to call all of their elements. This is the best I've got so far: #include <stdio.h>... (4 Replies)
Discussion started by: Azrael
4 Replies

2. Shell Programming and Scripting

Looping all subdierctories in multiple pipes

Hello friends, I want to run this code on every document in every sub-directory. tr -d '\n' < MulitpleInput.txt | awk '{gsub(/\. /,".\n");print}' | grep “\ I tried several looping techniques but couldn't get it to run in this example. Any ideas? Thank you (2 Replies)
Discussion started by: danbroz
2 Replies

3. Shell Programming and Scripting

Looping in case of duplicates

14`~abc`~9`~11 14`~abc`~9`~10 36`~ee`~7`~9 36`~ee`~8`~9 58`~rtt`~12`~7 70`~gff`~13`~8 86`~tyu`~6`~12 86`~tyu`~6`~13 92`~mjh`~5`~6 28`~jkl`~10`~DNA 32`~mjk`~SNA`~5 82`~jkli`~11`~DNA ------------------------------------ Field Seperator: `~ The concept is to start with SNA in the 3rd... (8 Replies)
Discussion started by: barath
8 Replies

4. Shell Programming and Scripting

Looping in case of duplicates ...

complinagetest () #function name { if ;then rm complins.dat fi touch complins.dat i=0 while read line do if ; then va=`grep -w "$line" datalins1.dat | awk BEGIN'{FS="\`~"}{if ( $3=="'$line'" ) {print $4}}'` i=$(($i+1)) varits=$(echo $va|awk -v varif="$i" '{print... (1 Reply)
Discussion started by: amitpaul01
1 Replies

5. Shell Programming and Scripting

Choose multiple conditions in case?

Hi all, I am attempting to create a shell script to optimize some routine process. I want this script can let user select the actions they want to do. But I met a problem that my script can only read one input and then do one action. Is it possible to let my script to run more than one... (2 Replies)
Discussion started by: kaiya
2 Replies

6. Shell Programming and Scripting

Looping for multiple directories

Hi experts, I am totally stuck with this. I run a looping "for" command for multiple directories, manually, I have done this : vfor dir in A B; do cp -p $dir/X.txt X-${dir}.txt done where A and B is directory name. However, I need to run for many directories. So I have tried this :... (7 Replies)
Discussion started by: guns
7 Replies

7. Shell Programming and Scripting

Multiple conditions in a CASE statement

is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be CASE $vendor OR $alias condition 1) statements; condition 2) statements; etc. esac but I keep... (25 Replies)
Discussion started by: Straitsfan
25 Replies

8. UNIX for Dummies Questions & Answers

Help in Array looping and creating multiple lines

hi Gurus, I'm a newbie in scripting please check my script if this is correct. I think there's something wrong with it but I;m not sure. I'm trying to create multiple lines using awk from external xml files but i want to add additonal info in the data manually Since i don't knwo how to... (0 Replies)
Discussion started by: sexyTrojan
0 Replies

9. Shell Programming and Scripting

multiple case

hi all im working in tcsh shell. In sh shell i write for example: case in $www 1 | 2 | 3) arguments;; 4 | 5 | 6) arguments;; esac can anybody tell me the equivalent to tcsh of 1 | 2 | 3)? (2 Replies)
Discussion started by: micromicrin
2 Replies

10. Programming

compile funtion

Hi, This is the first time, i am doing UNIX & C stuff. I have written one funtion like #include <stdio.h> seq(num) int num; { int i,sum; for (i=1; i<=num;i++) sum+=i; return(sum); } this seq funtion should have return values to unix script. like .. (4 Replies)
Discussion started by: sundarm
4 Replies
Login or Register to Ask a Question