How to lclear "expr: syntax error" eventhough everything looks fine?

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions How to lclear "expr: syntax error" eventhough everything looks fine?
# 1  
Old 03-18-2013
How to lclear "expr: syntax error" eventhough everything looks fine?

Hi All,

As per my knowledge in unix, my code looks fine. But still I am getting error (expr:syntax error). Please help me to resolve this error.

Script :

Code:
PRE_LBNO=0
PRE_DATE=0
TOT_PAY=0
TOT_REM=0
TOTAL=1
for Record_Type in `cut -c 1 Inputt.dat`
do
if [ $Record_Type = 'P' ];
then 
CURR_LBNO=` cut -c 46-50 Inputt.dat`
CURR_DATE=` cut -c 59-68 Inputt.dat`
PAY_AMT=` cut -c 69-79 Inputt.dat`
elif [ $Record_Type = 'R' ];
then 
REM_AMT=` cut -c 22-32 Inputt.dat`
fi
if [ "$PRE_LBNO" = "$CURR_LBNO" -a "$PRE_DATE" = "$CURR_DATE" ] || [ "$PRE_LBNO" = 0 -a "$PRE_DATE" = 0 ];
then
TOT_PAY=`expr $TOT_PAY + ${PAY_AMT}`
else
TOT_PAY=${PAY_AMT}
fi
if [ "$PRE_LBNO" = "$CURR_LBNO" -a "$PRE_DATE" = "$CURR_DATE" ] || [ "$PRE_LBNO" = 0 -a "$PRE_DATE" = 0 ];
then
TOT_REM=`expr $TOT_REM + ${REM_AMT}`
else
TOT_REM=${REM_AMT}
fi
if [ "$PRE_LBNO" = "$CURR_LBNO" -a "$PRE_DATE" = "$CURR_DATE" ];
then
TOTAL=`expr $TOTAL + 1`
else
TOTAL=${TOTAL}
fi
echo ${TOTAL}"|"${TOT_PAY}"|"${TOT_REM}"|"${CURR_LBNO}"|"${CURR_DATE} >> totals.txt
PRE_LBNO=`echo ${CURR_LBNO}`
PRE_DATE=`echo ${CURR_DATE}`
done

Thanks in advance

Moderator's Comments:
Mod Comment Use code tags, thanks. Check your PMs.

Last edited by zaxxon; 03-18-2013 at 08:34 AM.. Reason: code tags, see PM
# 2  
Old 03-18-2013
Sorry, but I am too lazy to check the code - would you be so nice and post the line number, that threw the error?
Maybe this helps you too.
Additionally you can add a set -x above that line and a set +x after it.
# 3  
Old 03-18-2013
Hi Zaxxon,

Even am not getting any line number. That is the problem
# 4  
Old 03-18-2013
Run the whole script. show us the error. That would help
# 5  
Old 03-18-2013
As PikK45 says and add set -x in the top of the script.
# 6  
Old 03-18-2013
If expr is complaining even though the expressions are fine, that means its inputs are not. Echo them before you call expr and see what they are.
# 7  
Old 03-18-2013
Your code looks fine, I think the problem might be with data.

Check the data once in Inputt.dat. The cut command you are using might be returning a String value. So you might be facing the error with expr.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

2. HP-UX

HP-UX: Shell Script giving " 0^J30: Syntax error"

Hi All, We are getting a very unique error while running a shell script on HP-UX box. Can somebody help in this regards? The shell script is working fine on linux/solaris box. Error: ++++++++++++++++++++++++ $/test.sh ./test.sh: 0^J30: Syntax error $ ++++++++++++++++++++++++ TIA.... (16 Replies)
Discussion started by: vai_sh
16 Replies

3. Shell Programming and Scripting

Error"syntax error at line 15: `end of file' unexpected"

While i m running below code, it is giving me the error"syntax error at line 15: `end of file' unexpected". Pls let me know what is wrong here..i tried many ways, but no luck dbSID="SWQE" usrname="apps" password="Wrgthrk3" count=0 while do sqlplus $usrname/$password@$dbSID... (5 Replies)
Discussion started by: millan
5 Replies

4. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token `"Hit <ENTER> to continue:"'

the below code will search attr string inside makefile under the modelno on given path. echo "Enter model no for searching string inside makefile" read inputs2 #find /pools/home_unix/sapte/work/models/model/$inputs2 -name "makefile" | xargs grep "attr" \; #;;I am getting below error.... (7 Replies)
Discussion started by: lathigara
7 Replies

6. Shell Programming and Scripting

Error with expr - "expr: syntax error"

Hi All, I'm writing a shell script in KSH, where I want to store the filename, total record count and actual record count of all the source files. The source files reside in 4 different sub-folders under the same root folder. Below is code: #!/usr/bin/ksh... (6 Replies)
Discussion started by: jagari
6 Replies

7. Shell Programming and Scripting

Bash (Ubuntu server): Syntax error: "|" unexpected in While-loop

Hello forum, I hope my problem is easy to solve for someone in here! My main task is to copy a large amount of imap-accounts from one server to another. There is a tool (Perl) called imapsync which does the job exellent. Unfortunately I'm only able to run it on one account at a time. After... (3 Replies)
Discussion started by: primaxx
3 Replies

8. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

9. Shell Programming and Scripting

"ld.so.1" error using a cron job | works fine otherwise

Hi, A cron job CJ invokes a shell script SC. SC internally invokes multiple perl scripts. One of the perl scripts deals with Accurev (i am using Accurev CLI). The first accurev command encountered is accurev merge -i <<file_name>> (file name has absolute path) When I run the perl script or... (1 Reply)
Discussion started by: singh
1 Replies

10. Shell Programming and Scripting

"syntax error at line 21 :'done' unexpected." error message"

I am trying to run the script bellow but its given me "syntax error at line 20 :'done' unexpected." error message" can someone check to see if the script is ok? and correct me pls. Today is my first day with scripting. Gurus should pls help out #!/bin/ksh # Purpose: Check to see if file... (3 Replies)
Discussion started by: ibroxy
3 Replies
Login or Register to Ask a Question