#28 Converting Temperatures

This script works with a variety of mathematical formulas, and an unusual input format, to translate between Fahrenheit, Celsius, and Kelvin. It's the first use of sophisticated mathematics within a script in this book, and you'll see where the experimentation in Script #9 that produced scriptbc proves a tremendous boon, as the same concept of piping an equation to bc shows up again here.

The Code

 #!/bin/sh # 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 [ $# -eq 0 ] ; then cat << EOF >&2 Usage: $0 temperature[F|C|K] where the suffix: F indicates input is ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.