coreutils
[Top][All Lists]
Advanced

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

Re: Request for enhancement: links to 'true' and 'false'


From: Jeffrey Streifling
Subject: Re: Request for enhancement: links to 'true' and 'false'
Date: Mon, 22 Apr 2013 13:21:14 -0600

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 <address@hidden> 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

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