Tuesday, September 16, 2014

Celsius To Fahrenheit Solver in Bash

This is another conversion of temperature that I wrote using Bash script. In my previous article I wrote a program that will ask the user to enter the temperature in Fahrenheit and then it will convert to its Celsius temperature equivalent. By this time it another way around from Celsius it will convert to its Fahrenheit value.

Take note in my sample bash program I always adding some functionalities like asking the user if the user wants again to run the program so that it can give a different value and then give us the different converted values. It makes our bash script more versatile in many ways. I hope you will find my sample bash script programs more useful in your learning how to program in bash in UNIX, MAC OS and Linux environment.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

Thank you very much.



Sample Output of Our Program

Program Listing

#!/bin/bash

# Celsius To Fahrenheit Solver
# Written By Mr. Jake R. Pomperada, MAED-IT
# Operating System : UBUNTU 14.04
# Date : September 16, 2014

start()
{
clear
echo -e "\n"
echo -e "\t (====== CELSIUS TO FAHRENHEIT SOLVER  =====)";
echo -e "\n"

read -p  "Please Enter Temperature in Celsius : " celsius_values
compute=$(echo "scale=2;((($celsius_values * 9/5 +32)))"|bc)

echo -e "\nTemperature in Celsius is $celsius_values\xe2\x84\x83 ."
echo -e "The equivalent temperature in Fahrenheit is $compute\xe2\x84\x83."

while true; do
  echo -e "\n"
  read -p "More (Y/N)? " answer
  case $answer in
       [Yy]* ) start;  break;;
       [Nn]* ) bye; break;;
       * ) echo "Please answer yes or no. ";;
  esac
done
}

bye()
{
echo -e "\n"
echo -e "\t Thank You For Using This Program.";
echo -e "\n\n";
}

start

No comments:

Post a Comment