Skip to content

Instantly share code, notes, and snippets.

@raku-cat
Created January 15, 2016 23:25
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 raku-cat/abad9c27fa64bbdd72ef to your computer and use it in GitHub Desktop.
Save raku-cat/abad9c27fa64bbdd72ef to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Script to determine the type of triangle based on side lenghts"
read -p "Enter a side length: " L1
read -p "Enter other side length: " L2
read -p "Enter the hypotenuse: " H
L1=$(echo "$L1*$L1"|bc)
L2=$(echo "$L2*$L2"|bc)
H=$(echo "$H*$H"|bc)
L=$(echo "$L1+$L2"|bc)
if (( $(bc <<< "$H==$L") )); then
TRIANGLE="right";
elif (( $(bc <<< "$H>$L") )); then
TRIANGLE="obtuse";
elif (( $(bc <<< "$H<$L") )); then
TRIANGLE="acute";
else echo "Unable to determine triangle type :C";
fi;
if [ -n ${TRIANGLE+x} ]; then
echo "The triangle is $TRIANGLE";
fi;
read -p "Test another triangle?[D:N] " REPLY
REPLY=${REPLY:=N}
case $REPLY in
"Y" | "y" )
bash triangle.sh
;;
"N" | "n" )
exit 0
;;
esac
exit 0
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment