Scripts for conversion between Fahrenheit, Celsius, and Kaishi (absolute temperature)

Source: Internet
Author: User
There are different mathematical formulas in the script for converting between Fahrenheit, Celsius, and Kaishi (absolute temperature. The input temperature can be either Fahrenheit, Celsius, or Kaishi (absolute temperature ). Code: 01 #! /Bin/sh0203 # convertatemp. sh -- Temperature Conversion script 04 # allow users to input Fahrenheit... there are different mathematical formulas in the script for converting between Fahrenheit, Celsius, and Kaishi (absolute temperature. The input temperature can be either Fahrenheit, Celsius, or Kaishi (absolute temperature ). Code: 01 #! /Bin/sh02 03 # convertatemp. sh -- Temperature Conversion script 04 # allow users to enter Fahrenheit (F), Celsius (C), and Kaishi (K) 05 # The output will get the equivalent temperature 06 07if [$ #-eq 0]; then08 cat <EOF> & 2 # here document, students, are you familiar with it? It is an interactive command used in scripts. 09 Usage: 'basename $ 0' temperature [F | C | K] 10 where the suffix: 11F indicates input is in Fahrenheit (default) 12C indicates input is in Celsius13K indicates input is in Kelvin14EOF15exit limit fi17 18 # sed-e's/unit in the original book [-[: digit:] * // g, after testing, I modified the temp in the 19 # sed-e's/[^-[[: digit:] * // g' original book, same as 20 unit = "$ (echo $1 | sed-e's/[[: digit:] * // g' | tr '[: lower:] ''[: upper:] ')" # obtain the Letter 21 temp = "$ (echo $1 | sed -E's/[^ [: digit:] * // g') "# obtain the number 22, 23, case $ {unit: = F} in # set the default variable value in 24 F) # formula for converting Fahrenheit to Celsius: Tc = (F-32) /1.825 farm = "$ temp" 26 cels = "$ (echo" scale = 2; ($ farm-32)/1.8 "| bc) "27 kelv =" $ (echo "scale = 2; $ cels + 273.15" | bc) "28; 29 C) # convert degrees Celsius to Tf = (9/5) * Tc + 3230 cels = $ temp31 kelv = "$ (echo" scale = 2; $ cels + 273.15 "| bc)" 32 farm = "$ (echo" scale = 2; (9/5) * $ cels) + 32 "| bc)" 33; 34 K) # degree Celsius = Kaishi-273.15, however After using Celsius to turn Fahrenheit Formula 35 kelv = $ temp36 cels = "$ (echo" scale = 2; $ kelv-273.15 "| bc) "37 farm =" $ (echo "scale = 2; (9/5) * $ cels) + 32" | bc) "38esac39 40 echo" Fahrenheit = $ farm "41 echo" Celsius = $ cels "42 echo" Kelvin = $ kelv "43 44 exit 0 run the script: although rarely used in Unix command lines, I (author of this book) still like this script because its input has intuitive features. The input is a numeric value with a suffix indicating the unit. In the future, you will see the same single-letter suffix in 66th scripts, which will convert the currency value. Running result: 01. /convertatemp. sh02Usage: convertatemp. sh temperature [F | C | K] 03 where the suffix: 04F indicates input is in Fahrenheit (default) 05C indicates input is in Celsius06K indicates input is in Kelvin07 08. /convertatemp. sh 100c09Fahrenheit = 212.0010 Celsius = 10011 Kelvin = 373.1512 13. /convertatemp. sh 100k14Fahrenheit =-279.6715 Celsius =-173.1516 Kelvin = 100 analysis script: You can also add an option to the script. Then you can run it like this:./converatemp. sh-c 100f to get the temperature at a moderate price of 100 degrees Fahrenheit.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.