What bc can do that expr can't is arbitrary precision, arbitrary scale,
arbitrary base arithmetic, complete with transcendentals.  You can do
tricks with bc that elude most other tools.  The benefit of doing math in
the shell is that everything is a string until stated otherwise, and you
can efficiently combine the strengths of various external specialized
 expression evaluators.  The pain is doing comparisons and branching.  The
most general method is probably, 'bc <<< "...comparison expression..." |
grep -q 1', or, portably, 'printf "...comparison expression...\n" |bc|grep
-q ^1$'.  Indeed, portable probably wins here despite being a little less
expressive, and probably justifies cancelling my feature request . . .


On Mon, Apr 22, 2013 at 12:34 PM, Bob Proulx <[email protected]> wrote:

> Eric Blake wrote:
> > Bob Proulx wrote:
> > > But even expr is now obsoleted by built in shell math.  Use ((...)) to
> > > perform the math in the shell with no external program calls.
> >
> > In bash, yes, but not portable.  $(()) is standardized by POSIX, but
> > (()) is not, and has some surprising corner cases because it is not
> > standardized.
>
> Thanks for that correction.  With that in mind then am I justified in
> sticking with my old traditional expr use?  It works everywhere!  :-)
>
> Bob
>

Reply via email to