[olug] Doing math in /bin/bash
Kevin
sharpestmarble at gmail.com
Sat May 7 15:02:42 UTC 2011
Why involve anything other than bash?
[kevin at hostname ~]$ A=5
[kevin at hostname ~]$ C=3
[kevin at hostname ~]$ B=4
[kevin at hostname ~]$ echo $(($A*$C/$B))
3
[kevin at hostname ~]$
On Sat, May 7, 2011 at 09:56, 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