Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Author -- MR
- #Date modified -- 2/11/14
- fah_to_cel()
- {
- echo
- echo -n "Enter fahrenheit: "
- read fah
- echo
- a=32
- b=0.56
- echo -n "$fah FAHRENHEIT in CELSIUS is: "
- echo -n "$fah $a $b" | awk '{ print ($1-$2) * $3 }'
- echo
- }
- cel_to_fah()
- {
- echo
- echo -n "Enter celsius: "
- read cel
- echo
- c=1.8
- d=32
- echo -n "$cel CELSIUS in FAHRENHEIT is: "
- echo -n "$cel $c $d" | awk '{ print ($1*$2) + $3 }'
- echo
- }
- help()
- {
- echo
- echo "PROGRAM DESCRIPTION"
- echo
- echo "This program converts temperature from C to F, vice versa"
- echo
- }
- menu()
- {
- while [ "$choice" != "3" ]
- do
- echo
- echo "~~~~What do you want to do?~~~~"
- echo "================================"
- echo "1. Convert Fahrenheit to Celsius"
- echo "2. Convert Celsius to Fahrenheit"
- echo "3. Exit"
- echo "================================"
- echo
- echo -n "Enter choice: "
- read choice
- echo
- if [ "$choice" == "1" ]
- then
- fah_to_cel
- elif [ "$choice" == "2" ]
- then
- cel_to_fah
- elif [ "$choice" == "3" ]
- then
- echo "Goodbye"
- echo
- else
- echo "Invalid choice"
- fi
- done
- }
- if [ "$#" -eq 0 ]
- then
- menu
- else
- while getopts hcfi j
- do
- case $j in
- h) help;;
- c) cel_to_fah;;
- f) fah_to_cel;;
- i) menu;;
- esac
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement