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 :

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

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.

Hi Zaxxon,

Even am not getting any line number. That is the problem

Run the whole script. show us the error. That would help

As PikK45 says and add set -x in the top of the script.

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.

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.