Maybe something like this:
Code:
$
$ # 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