help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: summation in dc


From: Karl Berry
Subject: Re: summation in dc
Date: Wed, 11 Aug 2004 14:44:13 -0400

    A frequent task I have is to sum a series of numbers.

I've had the same problem making bc and dc do what I want without fuss.
I've found it is simpler to use awk:

#!/bin/sh
# Exit status is zero if condition evaluates to nonzero, and the converse.
exec gawk "BEGIN { answer = $*; printf \"%.3f\\n\", answer; exit !(answer); }"

Supposing the script is called rexpr, then rexpr 1+2+3 on the cmdline
will yield the right results.  (sed or perl or whatever should be able
to transform the list into an expression.)

Sorry if you already know all this and are just interested in ?c.

Best,
k




reply via email to

[Prev in Thread] Current Thread [Next in Thread]