expr command

hi guys....

i hava a command expr... where i m adding a value in a loop
like
Tc=`expr $Tc\+ $l`
where
Tc is declred as a variable and every time l contains a new vaue
if
Tc =0 initially
and l =2
Tc should be equal to 0+ 2
and then
l = 4
Tc = 2+4

and dispaly as 6

but after on iteration it is not adding up the value...

any reason for it

why is the \+ ?

Could be just,
Tc=`expr $Tc+ $l`

Could you please post your script if possible ?

It helps to post what answer you're getting as well. It might point to what the problem is.

Carl

hi
this is the script

for i in `ls q*.txt`
do
l=0
tc=0
var=`tail -1 $i`
l=`echo $var | cut -d'|' -f2`
tc=`expr $tc+$l`
done

every time it gives the first answer
i.e if l =2
for the first time
it prints 2 always
if l = 6 next time
tc = 8 is expected
but displays 2 only

tc=0
for i in `ls q*.txt`
do
  l=`tail -1 $i | cut -d'|' -f2`
  tc=`expr $tc + $l`
  echo $tc
done

Do not do that. Not only is ls unnecessary and slow, but it will break your script if there are any spaces or other pathological characters in any filenames.

Use:

for i in q*.txt

You reset $tc to 0 on every iteration of the loop. Set it before the loop.