#!/bin/bash # # $Id:$ # # 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 http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- # Fahrenheit and Celsius Temperature Scales more info: # http://en.wikipedia.org/wiki/Temperature_conversion_formulas # -------------------------------------------------------------------- function convert_c2f { echo -n "Enter temperature (C) : " read tc # formula Tf=(9/5)*Tc+32 tf=$(echo "scale=20; ((9/5) * $tc) + 32" | bc) printf "\n%0.2f degrees C = %0.2f degrees F\n\n" $tc $tf } function convert_f2c { echo -n "Enter temperature (F) : " read tf # formula Tc=(5/9)*(Tf-32) tc=$(echo "scale=20; (5/9) * ($tf - 32)" | bc) printf "\n%0.2f degrees F = %0.2f degrees C\n\n" $tf $tc } function display_menu { echo echo "*** Converting between the different temperature scales ***" echo " 1. Convert Celsius temperature into Fahrenheit" echo " 2. Convert Fahrenheit temperatures into Celsius" echo " 3. Quit the program" echo echo -ne "Select your choice (1, 2 or 3) : " } function quit_program { echo "Finished." echo exit 0 } while : ; do display_menu read choice echo case $choice in 1) convert_c2f continue ;; 2) convert_f2c continue ;; 3) quit_program break ;; *) echo "Please select 1, 2 or 3 only" echo echo -e "** Error: '$choice' is not valid.\n" ; continue ;; esac done # End of File