if [ $# -eq 0 ];then
cat << EOF >&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
fi
unit="$(echo $1|sed -e 's/[-[:digit:]]*//g' | tr '[:lower:]' '[:upper:]')"
temp="$(echo $1|sed -e 's/[^-[:digit:]]*//g')"
case ${unit:=F}
in
F)
farn="$temp"
cels="$(echo "scale=2;($farn - 32)/1.8"|bc)"
kelv="$(echo "scale=2;$cels+273.15"|bc)"
;;
C)
cels="$temp"
kelv="$(echo "scale=2;$cels+273.15"|bc)"
farn="$(echo "scale=2;(1.8*$cels)+32"|bc)"
;;
K)
kelv=$temp
cels="$(echo "scale=2;$kelv-273.15"|bc)"
farn="$(echo "scale=2;(1.8*$cels)+32"|bc)"
;;
*)
echo "Given temperature unit is not supported"
exit 1
esac
echo "Fahrenheit =$farn"
echo "Celsius =$cels"
echo "Kelvin =$kelv"
exit 0
运行结果