Adding Variables

Hi.

I have a for loop that I use to extract integer values in a shell script (ksh). Now, I would like to add the values. My preference, from my c programming days, would be to do something like the commented out line below in the for loop. However, this is not recognised. So I use the line shown (TOTALWORK=$TOTALWORK+$WORKDONE) but this is concatenating the values (See output below).

    let WORKDONE=0
    let TOTALWORK=0

    # calculate the total work done
    for WORKDONE in `grep "Records to Delete" ${LOGFILE}|cut -d':' -f5|cut -d' ' -f2`
    do
        #TOTALWORK+=$WORKDONE
        TOTALWORK=$TOTALWORK+$WORKDONE
    done

The output is:

TOTAL WORK DONE :0+10+5

So i guess I am not adding but concatenating the values. So the varables must be getting treated as strings rather than integer values? I don't immediately see what I have done wrong here? Any advice gratefully received.

Thanks in advance.

try:

TOTALWORK=$((  $TOTALWORK + $WORKDONE  ))

the $(( )) construct does integer math with operators: + - / * %, just like C.

Brilliant. Thanks for the help on that. Works perfectly now.

M.