Created
February 14, 2022 19:34
-
-
Save CodeMaster7000/62d2b8149df390856d5d95ea4f21c469 to your computer and use it in GitHub Desktop.
A Shell script that converts Fahrenheit temperatures into Celsius and vice versa.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "*** Converting between different temperature units ***" | |
echo "1. Convert Celsius temperatures into Fahrenheit" | |
echo "2. Convert Fahrenheit temperatures into Celsius" | |
echo -n "Select your choice (1-2): " | |
read choice | |
if [ $choice -eq 1 ] | |
then | |
echo -n "Enter temperature (C): " | |
read tc | |
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc) | |
echo "$tc C = $tf F" | |
elif [ $choice -eq 2 ] | |
then | |
echo -n "Enter temperature (F): " | |
read tf | |
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc) | |
echo "$tf = $tc" | |
else | |
echo "Please select 1 or 2 only" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment