[olug] Doing math in /bin/bash
Chad Homan
choman at gmail.com
Sat May 7 15:02:53 UTC 2011
second jay's response. I was just gonna say that :(
but on your gcalctool example, try quoting the equation
COUNT=`gcalctool -s "($a *$b) / $c"`
--
Chad, CISSP, Star 500
Better Health? Better Wealth? <http://blackdiamondbuilder.com/choman>
On Sat, May 7, 2011 at 9:56 AM, jay swackhamer <reboottheuser at gmail.com>wrote:
> COUNT=`echo "${A} * ${C} / ${B}" | bc`
>
> On Sat, May 7, 2011 at 9:55 AM, jay swackhamer <reboottheuser at gmail.com
> >wrote:
>
> > You could use the 'basic calculator' 'bc' or expr
> >
> > COUNT=0
> > COUNT=`expr ${A} \* ${C}`
> > COUNT=`${COUNT} / ${B}`
> >
> >
> > or
> >
> > echo "${A} * ${C} / ${B}" | bc
> >
> >
> >
> >
> >
> > On Sat, May 7, 2011 at 9:48 AM, Kevin D. Snodgrass <
> kdsnodgrass at yahoo.com>wrote:
> >
> >> I'm trying to do a calculation in a bash script. Looked at dc, but
> looks
> >> more complicated than it's worth. Then tried gcalctool. I get exactly
> what
> >> I want except for one thing, I just need the "whole" number part. I.e.,
> >> (a/b)*c mod 1.
> >>
> >> Tried:
> >> declare -i COUNT
> >> COUNT=`gcalctool -s $A*$C/$B`
> >>
> >> Was hoping it could be that easy. :-)
> >>
> >>
> >> Any nifty ideas?
> >>
> >> Kevin D. Snodgrass
> >>
> >> _______________________________________________
> >> OLUG mailing list
> >> OLUG at olug.org
> >> https://lists.olug.org/mailman/listinfo/olug
> >>
> >
> >
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug
>
More information about the OLUG
mailing list