Skip to content

Instantly share code, notes, and snippets.

@hugot
Last active February 13, 2017 20:14
Show Gist options
  • Save hugot/19de1a2771ac81c4917e97afa1263bef to your computer and use it in GitHub Desktop.
Save hugot/19de1a2771ac81c4917e97afa1263bef to your computer and use it in GitHub Desktop.
I am doing python tutorials in bash, call me crazy
#!/usr/bin/env bash
#----- Functions -----
divide() {
echo $(( $(($1 * 100)) / $2))
}
multipleOfFour() {
result=$(divide $1 2)
[[ ${result#*0} == *0* ]]
}
even() {
result=$(divide $1 4)
[[ ${result#*0} == *0* ]]
}
checkResultIsEven() {
result=$(divide $1 $2)
if even $result; then
echo Dividation resulted in an even number
else
echo Dividation resulted in an uneven number
fi
}
#----- application logic -----
while true; do
echo enter a number
read number
if multipleOfFour $number; then # Exercise 2
echo your number is a multiple of four
elif even $number; then # Exercise 1
echo your number is even
else
echo Your number is uneven
fi
# Exercise 3
echo enter two numbers, one to check, one to divide by, in that order
read num1 num2
checkResultIsEven $num1 $num2
done
@hugot
Copy link
Author

hugot commented Feb 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment