Reputation: 125
I know this is probably really easy and I am just putting to much thought into it but I need to create a Bash script that will convert Celsius to Fahrenheit with this equation:
f = (9/5)c+32
How would I do this? Using just expr
doesn't work because it won't use floating point. How do I do this equation? Using bc
?
Upvotes: 3
Views: 3190
Reputation: 143081
This would be the easiest, I believe:
echo $(($c*9/5+32))
(and yes, floating point will be lost, you may add a couple of zeros and work on the string, tho).
Upvotes: 1
Reputation: 80761
If you want to use bc try this :
echo "9*$c/5+32" | bc -l
Upvotes: 3
Reputation: 249133
xdg-open "http://www.google.com/search?q=${TEMP}+C+in+F"
Too silly? Check out http://www.linuxjournal.com/content/floating-point-math-bash
Upvotes: 0
Reputation: 36049
You (normally) don't need floating point arithmetic for this to work, if rounding errors are not critical and you don't need floating-point precision:
expr 9 '*' $c / 5 + 32
Upvotes: 1