[olug] Doing math in /bin/bash

jay swackhamer reboottheuser at gmail.com
Sat May 7 14:56:28 UTC 2011


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
>>
>
>



More information about the OLUG mailing list