Shell Script Convert Fahrenheit to Celsius Temperature ( Celsius to Fahrenheit Temperature )

in Categories Decision Making, Shell Math last updated February 3, 2009

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

# Shell script to convert Fahrenheit to Celsius Temperature or Celsius 
# to Fahrenheit Temperature
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
# Fahrenheit and Celsius Temperature Scales more info:
# --------------------------------------------------------------------
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 ]
	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 ]
	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"
	echo "Please select 1 or 2 only"
	exit 1

Share this on:

3 comment

    Have a question? Post it on our forum!