Condition error!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Condition error!
# 1  
Old 08-11-2011
Condition error!

Hi Guys,

Can you please help me to check if my condition is correct.

Code:
if [ `${ECHO_CMD} "${SE_USERID_LUZON_2}" | ${GREP_CMD} "globelines.com.ph$" | ${WC_CMD} -l` -gt "0" ] && [ `${ECHO_CMD}
"${SE_USERID_LUZON_2}" | ${WC_CMD} -c` -gt "1" ]
        then
if [ `echo "${SE_USERID_LUZON_5}" | grep "^Y" | wc -l ` -gt "0" ]; then
        # active
        SE_USERID_LUZON_5="A"
elif [ `echo "${SE_USERID_LUZON_5}" | grep "^N" | wc -l ` -gt "0" ]; then
        # not active
        SE_USERID_LUZON_5="D"
${ECHO_CMD} "${SE_USERID_LUZON_2}\t${SE_USERID_LUZON_3}\t${SE_USERID_LUZON_5}\t${SE_USERID_LUZON_6}\t${SE_USERID_LUZON_1
0}" >> ${SE_IN_PATH}${SE_IN_FILE}.valid
        SE_BCPIN_BUFFER="1"
        #dapat 1
else
        ${ECHO_CMD} "${SE_USERID_LUZON_FILE}" >> ${SE_IN_PATH}${SE_IN_FILE}.INVALID
done < ${SE_IN_PATH}${SE_IN_FILE}
fi # -- MOVE temp as txt
fi # -- MOVE file to backup

Thanks,
# 2  
Old 08-11-2011
It's very hard (if possible at all) to look at some script fragment with fancy logic and decide whether it is right.
I can say only that this line is not at place (and of course I can't say where it should be exactly):
Code:
done < ${SE_IN_PATH}${SE_IN_FILE}

If you follow a good indentation style it would be easier to catch.

---------- Post updated at 11:19 AM ---------- Previous update was at 11:05 AM ----------

A good style is to indent any sub-compound statement and maybe blank lines before and after long or complex compound statements. Your outline is:
Code:
if ...

  if ...
    ...
  elif
    ...
  else
    ...

done... #???

  fi
fi

# 3  
Old 08-11-2011
so that's means my code is incorrect? can you please help me what's wrong in my condition? thx

is this ok?

if...
elif...
elif..
else..

Thanks,

---------- Post updated at 01:17 PM ---------- Previous update was at 12:52 PM ----------

how about this.

Code:
if [ `${ECHO_CMD} "${SE_USERID_LUZON_2}" | ${GREP_CMD} "globelines.com.ph$" | ${WC_CMD} -l` -gt "0" ] && [ `${ECHO_CMD}
"${SE_USERID_LUZON_2}" | ${WC_CMD} -c` -gt "1" ] then
        if [ `echo "${SE_USERID_LUZON_5}" | grep "^Y" | wc -l ` -gt "0" ]; then
                # active
                SE_USERID_LUZON_5="A"
        elif [ `echo "${SE_USERID_LUZON_5}" | grep "^N" | wc -l ` -gt "0" ]; then
                # not active
                SE_USERID_LUZON_5="D"

        ${ECHO_CMD} "${SE_USERID_LUZON_2}\t${SE_USERID_LUZON_3}\t${SE_USERID_LUZON_5}\t${SE_USERID_LUZON_6}\t${SE_USERID
_LUZON_10}\t${SE_USERID_LUZON_11}" >> ${SE_IN_PATH}${SE_IN_FILE}.valid

        SE_BCPIN_BUFFER="1"
        #dapat 1
else
        ${ECHO_CMD} "${SE_USERID_LUZON_FILE}" >> ${SE_IN_PATH}${SE_IN_FILE}.INVALID

done < ${SE_IN_PATH}${SE_IN_FILE}
fi # -- MOVE temp as txt
fi # -- MOVE file to backup

it says error Syntax error `done' is not expected. T_T

Thanks
# 4  
Old 08-11-2011
in your code you use while or for loop ?

what is the need of done here ?

Code:
 
done < ${SE_IN_PATH}${SE_IN_FILE}

post the full code

if you use while or for loop and you expect the if condtion should be there within the for or while loop, then your done statement should be in last

Code:
 
fi # -- MOVE temp as txt
fi # -- MOVE file to backup
done < ${SE_IN_PATH}${SE_IN_FILE}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

If condition is not working and getting error

Hi Team, If condition is not working properly and getting below error # ./score1.sh Enter your score ('q' for quit): 102 Enter your score ('q' for quit): q ./score1.sh: line 9: q: integer expression expected Average is: 102%. Exit. Actual code # Calculate the average of given... (3 Replies)
Discussion started by: Torrid
3 Replies

2. Shell Programming and Scripting

If condition giving syntax error. Need help.

Hi, I have an if condition on executing it is giving syntax error as below: -------------------------------------------------------------------------------------- line 61: syntax error in conditional expression ./play_test.sh: line 61: syntax error near `]' ./play_test.sh: line 61: ` if... (2 Replies)
Discussion started by: ramki067
2 Replies

3. Shell Programming and Scripting

Handling standard error in condition

Testing this with KSH on RHEL The bellow code works but i can't seem to handle the exit status of the unix command when it fails... i wanted to put something like >/dev/null 2>&1 to manage standard output and standard error but it changes my logic and the code doesn't work cause it doesn't... (11 Replies)
Discussion started by: maverick72
11 Replies

4. Shell Programming and Scripting

Error: if condition

please follow below code if ; then its giving me an error as "test1.sh: line 3: r=$(eval echo '$lck_'$TABLE != "") if can anyone tell me how to do inside if condition...with out use any variable.. TIA (6 Replies)
Discussion started by: gnnsprapa
6 Replies

5. UNIX for Dummies Questions & Answers

error in if condition

Hi All, I need to compare the header of the input files which can be comma demilited, tild(~) or Pipr(|) seperated file. I am comparing the file header by taking 1st row and comparing it with input row: Below is the actual code:(ksh script) if then echo $dat >>... (4 Replies)
Discussion started by: abhi_123
4 Replies

6. Shell Programming and Scripting

while condition error:

I'm trying to run following code: while do echo "Hello World" done but I'm getting error on first line: ./test: line 1: syntax error near unexpected token `(' can anyone please tell me who can i run this loop. Also please tell me what will be syntax of do while loop in case i... (11 Replies)
Discussion started by: kashif.live
11 Replies

7. Shell Programming and Scripting

Error in if condition string comparison

Hello all! I need help in debugging following script. I have no idea where I am going wrong. #!/bin/bash for p1 in A1 TM MP do for p2 in A1 TM MP do for mp1 in N1 N2 do for mp2 in N1 N2 do for mp3 in N1 N2 do for mp4 in N1 N2 do for... (7 Replies)
Discussion started by: RLOA
7 Replies

8. Shell Programming and Scripting

If condition error-please debug my script

Hi All, I have a script which is based on calculating current time The script looks like this: whenever i try to run the script it gives me error:Please advice wherther i have made mistake with if condition or with for loop?? The code : set -x #!/usr/bin/ksh set -x... (7 Replies)
Discussion started by: usha rao
7 Replies

9. Shell Programming and Scripting

error in if-else condition

Hi.. Im using the following script to find whether the present day is monday or not. If it is monday it has to do a specific set of things. #!/bin/sh Present_Date=`date` LOAD_DAY=`date -d "$Present_Date" | cut -d " " -f 1` echo $LOAD_DAY if ;then echo "Monday" #statements;... (6 Replies)
Discussion started by: abala
6 Replies

10. Shell Programming and Scripting

When running if condition, getting the following error

Hi All, My input file name is 1.sh the contents of file are cat status2.txt | while read filename do echo "$filename" echo "first content of the file is ${filename}" echo "second content of the file is ${filename}" echo "second content of the file is ${filename}" if } -eq 0 -a... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies
Login or Register to Ask a Question