In: Computer Science
****USING BASH****
Write a function that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin.
Here is a script that takes Celsius from the user and then converts Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin
Formula:
Celsius to Fahrenheit - (0°C × 9/5) + 32 = 32°F
Fahrenheit to Celsius - (32°F − 32) × 5/9 = 0°C
Celsius to Kelvin - 0°C + 273.15 = 273.15K
Fahrenheit to Kelvin - (32°F − 32) × 5/9 + 273.15 = 273.15K
echo
echo command in linux is used to display line of text/string that are passed as an argument
read
read command in Linux system is used to read from a file descriptor
#!/bin/bash
functionn () {
echo -n "Enter temperature (C) : "
read tc
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
tk=$(echo "scale=2;$tc + 273.15" |bc)
echo "$tc Celsius = $tf Fahrenheit"
echo "$tc Celsius = $tk Kelvin"
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
tkk=$(echo "scale=2;(5/9)*($tf-32) + 273.15"|bc)
echo "$tf Fahrenheit = $tc Celsius"
echo "$tf Fahrenheit = $tkk Kelvin"
}
function
Output:
Hope this may help you.
Thank you ??