Applied Programming/Variables/Bash

variables.sh

edit
#!/bin/bash

# This program converts a Fahrenheit temperature to Celsius.
#
# Input:
#   Fahrenheit temperature (Integer)
#
# Output:
#   Fahrenheit temperature (Integer)
#   Celsius temperature (Integer)
#
# Example:
#   Enter Fahrenheit temperature:
#   122
#   122° Fahrenheit is 50° Celsius
#
# References:
#   https://www.mathsisfun.com/temperature-conversion.html
#   https://en.wikibooks.org/wiki/Bash_Shell_Scripting
#   http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
#   https://en.wikiversity.org/wiki/Programming_Fundamentals/Introduction/Bash
#   https://en.wikiversity.org/wiki/Programming_Fundamentals/Variables/Bash
#   https://linuxhint.com/30_bash_script_examples/
#   https://ryanstutorials.net/bash-scripting-tutorial/bash-input.php
#   https://google.github.io/styleguide/shell.xml

echo -n "Enter Fahrenheit temperature: "
read fahrenheit

celsius=$((($fahrenheit - 32) * 5 / 9))

echo "$fahrenheit° Fahrenheit is $celsius° Celsius"

Try It

edit

Copy and paste the code above into one of the following free online development environments or use your own Bash compiler / interpreter / IDE.

See Also

edit