[ale] Shell script

Fulton Green me at FultonGreen.com
Wed Sep 27 18:13:01 EDT 2000


------------------rip here-------------------
#!/bin/sh
numberfile="$1"
calcstring=""
for mynumber in `cat $numberfile` ; do
  if [ -z "$calcstring" ] ; then
    calcstring="($mynumber)"
  else
    calcstring="($calcstring)+($mynumber)"
  fi
done

(echo "scale=2" && echo "$calcstring") | bc
------------------rip here-------------------

On Wed, Sep 27, 2000 at 05:09:59PM -0400, Brian J. Dowd wrote:
> Does anyone have a bash script which will
> sum all the numbers in a file?
> They aren't integers (which rules out 'expr')
> Each is on a separate line. Example:
> -45.23
> 55.6
> 123.44
> ...
> I can't seem to make 'bc' work...
> 
> --
> To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list