foor loop is not working while assigning to variable

Hi All,

While executing following for loop in unix, it is working fine.

sum=0
tot_amt=`for i in `cat amt`
do
sum=`echo "$sum + $i"|bc`
done`

But if i assing this loop in a variable it is not working. The error is so and done is unexpected.

tot_val=`sum=0;tot_amt=`for i in `cat amt` do sum=`echo "$sum + $i"|bc` done`

can someone tell me where i have made an mistake. i think it is with " ` ".

Regards,

Amit

sorry..

tot_val=`sum=0; for i in `cat amt` do sum=`echo "$sum + $i"|bc` done`

this is not working...

Without really looking into this at all...have you tried

tot_val=`sum=0;tot_amt=`for i in $(cat amt) do sum=`echo "$sum + $i"|bc` done`

Hi Deco

tot_val=`sum=0;tot_amt=`for i in $(cat amt) do sum=`echo "$sum + $i"|bc` done``

it says teletype mismatch. So i have declare the variable before for loop.

tot_val=`sum=0;tot_amt=0;tot_amt=`for i in $(cat amt) do sum=`echo "$sum + $i"|bc` done``

It says: command i not found. I do not know wht it is taking i as a command.