Shell Ccript Convert Fahrenheit to Celsius Temperature ( Celsius to Fahrenheit Temperature )
Posted in Decision Making » Shell Math
Temperature is a physical property of a system that underlies the common notions of hot and cold; something that is hotter generally has the greater temperature. Temperature is measured with thermometers that may be calibrated to a variety of temperature scales. In most of the world , the degree Celsius scale is used for most temperature measuring purposes. The Celsius scale, is commonly used for scientific work. The Fahrenheit Scale is used in USA and some other countries.
Temperature Conversions
- Fahrenheit to Celsius temperature conversion formula : C = (F - 32) x 5/9
- Celsius to Fahrenheit temperature conversion formula : F = (C x 9/5) + 32
See wikipedia article about temperature conversion formulas.
Temperature Conversions Shell Script
#!/bin/bash # Shell script to convert Fahrenheit to Celsius Temperature or Celsius # to Fahrenheit Temperature # ------------------------------------------------------------------------- # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- # Fahrenheit and Celsius Temperature Scales more info: # http://en.wikipedia.org/wiki/Temperature_conversion_formulas # -------------------------------------------------------------------- echo "*** Converting between the different temperature scales ***" echo "1. Convert Celsius temperature into Fahrenheit" echo "2. Convert Fahrenheit temperatures into Celsius" echo -n "Select your choice (1-2) : " read choice if [ $choice -eq 1 ] then echo -n "Enter temperature (C) : " read tc # formula Tf=(9/5)*Tc+32 tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc) echo "$tc C = $tf F" elif [ $choice -eq 2 ] then echo -n "Enter temperature (F) : " read tf # formula Tc=(5/9)*(Tf-32) tc=$(echo "scale=2;(5/9)*($tf-32)"|bc) echo "$tf = $tc" else echo "Please select 1 or 2 only" exit 1 fi
Download - Email this to a friend - Printable version
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bc command, celsius to fahrenheit, conversion formulas, degree celsius, fahrenheit scale, fahrenheit temperature, fahrenheit temperatures, if command, mathematics, temperature conversion, temperature conversions, temperature scales, thermometers ~ Last updated on: April 4, 2008

