Using bc to assign value

Friends here is code which is used to add floating point using bc, but I m not getting any output instead some errors.

1 #!/bin/bash

 
  4 if [ -c /proc/$$/fd/0 ]
  5 then
  6    echo "Our input is from a Device"
  7         while read myline
  8         do
  9
 10         total= `echo $total + $myline |bc`
 11         #((total=$total+ $myline))
 12         done
 13
 14 elif [ -p /proc/$$/fd/0 ]
 15 then
 16
 17    echo "Our input is from a pipe"
 18         while read myline2
 19         do
 20         total= `echo $total + $myline |bc`
 21         #((total= $total+ $myline2))
 22         done
 23 elif [ -f /proc/$$/fd/0 ]
 24 then
 25
 26    echo "Our input is from a file"
 27         while read myline3
 28         do
 29         add=+
 30         $(($total $add $myline))| bc
 31         #echo $total $myline
 32         #total= echo `$total $add $myline |bc`
 33         #((total= $total+ $myline))
 34         done
 35
 36
37
38   echo "Error"
 39         break;
 40 fi
 41
 42 echo total is $total

Maybe something like this:

$ 
$ # display the file "num" that has floating-point numbers, one per line
$                                                                    
$ cat num                                                            
2.1                                                                  
3.4                                                                  
4.6                                                                  
5.2                                                                  
6.3                                                                  
$
$ # display the script
$
$ cat test_scr.sh
#!/bin/bash
NUMFILE=$1
total=0
if [ -c $NUMFILE ]
then
  echo "Our input is from a Device"
  while read LINE; do
    total= `echo $total + $LINE | bc`
  done < $NUMFILE
elif [ -p $NUMFILE ]
then
  echo "Our input is from a pipe"
  while read LINE; do
    total= `echo $total + $LINE | bc`
  done < $NUMFILE
elif [ -f $NUMFILE ]
then
  echo "Our input is from a file"
  while read LINE; do
    total=`echo $total + $LINE | bc`
  done < $NUMFILE
fi
echo total is $total
$
$ # test the script, passing "num" as input
$
$ . test_scr.sh num
Our input is from a file
total is 21.6
$
$

HTH,
tyler_durden

Thanks tyler_durden. A good job done, yea it makes more sense thanks again :b: