Last active
June 24, 2021 12:05
-
-
Save waldekmastykarz/e7043d01a85b402cffe2faf987ab8e04 to your computer and use it in GitHub Desktop.
Celsius to Fahrenheit and vice versa in zsh
This file contains 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
# usage | |
# $ deg 10c # Celsius to Fahrenheit | |
# 50.0 | |
# | |
# $ deg 115f # Fahrenheit to Celsius | |
# 46 | |
deg() { | |
unit=${1:(-1)} | |
d=${1:0:(-1)} | |
if [ $unit = c ] | |
then | |
echo "scale=0; ($d * 1.8) + 32" | bc -l | |
else | |
echo "scale=0; ($d - 32) / 1.8" | bc -l | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment