BASH question

Khoa Ton khoa at puresynergy.com
Thu Sep 7 07:49:39 UTC 2006


M.Lewis wrote:
> Andy Green wrote:
>> M.Lewis wrote:
>>>
>>> I thought this was simple, but I've not yet been able to figure out 
>>> what is wrong.
>>>
>>> #!/bin/sh
>>>
>>> PERMINUTE=$((28.95/432000))
>>
>> No floating point support :-)  But even then, be liberal with spaces
>>
>> PERMINUTE=$(( 29 / 432000 ))
>>
>> -Andy
>>
> 
> Thanks Andy, that resolved the error, but returns $PERMINUTE as 0. It 
> should be something like .00067xxxxx. Is there a way to do that?
> 
> Thanks,
> Mike
> 
> 

This should work for you:

PERMINUTE=$(echo "5 k 28.95 432000 / p" | dc)

I find dc (man dc) very useful for floating point arithmetic.

Khoa




More information about the fedora-list mailing list