Skip to content

Instantly share code, notes, and snippets.

@waldekmastykarz
Last active June 24, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldekmastykarz/e7043d01a85b402cffe2faf987ab8e04 to your computer and use it in GitHub Desktop.
Save waldekmastykarz/e7043d01a85b402cffe2faf987ab8e04 to your computer and use it in GitHub Desktop.
Celsius to Fahrenheit and vice versa in zsh
# 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