#!/bin/bash # convertatemp--Temperature conversion script that lets the user enter # a temperature in Fahrenheit, Celsius, or Kelvin and receive the # equivalent temperature in the other two units as the output if test $Argc -eq 0 { cat << """ >&2 Usage: $0 temperature[F|C|K] where the suffix: F indicates input is in Fahrenheit (default) C indicates input is in Celsius K indicates input is in Kelvin """ > !2 Usage: $0 temperature[F|C|K] where the suffix: F indicates input is in Fahrenheit (default) C indicates input is in Celsius K indicates input is in Kelvin EOF exit 1 } setglobal unit = $[echo $1|sed -e 's/[-[:digit:]]*//g' | tr '[:lower:]' '[:upper:]] setglobal temp = $[echo $1|sed -e 's/[^-[:digit:]]*//g] match $(unit:=F) { with F # Fahrenheit to Celsius formula: Tc = (F - 32) / 1.8 setglobal farn = $temp setglobal cels = $[echo "scale=2;($farn - 32) / 1.8" | bc] setglobal kelv = $[echo "scale=2;$cels + 273.15" | bc] with C # Celsius to Fahrenheit formula: Tf = (9/5)*Tc+32 setglobal cels = $temp setglobal kelv = $[echo "scale=2;$cels + 273.15" | bc] setglobal farn = $[echo "scale=2;(1.8 * $cels) + 32" | bc] with K # Celsius = Kelvin - 273.15, then use Cels -> Fahr formula setglobal kelv = $temp setglobal cels = $[echo "scale=2; $kelv - 273.15" | bc] setglobal farn = $[echo "scale=2; (1.8 * $cels) + 32" | bc] with * echo "Given temperature unit is not supported" exit 1 } echo "Fahrenheit = $farn" echo "Celsius = $cels" echo "Kelvin = $kelv" exit 0