Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy Linux Bash Script

Tags:

bash

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?

like image 640
austinminn Avatar asked Feb 06 '26 08:02

austinminn


2 Answers

If you want to use bc try this :

echo "9*$c/5+32" | bc -l
like image 142
Cédric Julien Avatar answered Feb 07 '26 20:02

Cédric Julien


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 
like image 27
thiton Avatar answered Feb 07 '26 20:02

thiton