Skip to content

Instantly share code, notes, and snippets.

@earlonrails
Last active November 25, 2022 11:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earlonrails/1339884 to your computer and use it in GitHub Desktop.
Save earlonrails/1339884 to your computer and use it in GitHub Desktop.
Fizz Buzz in bash! Hooray!
#!/bin/bash
x=1
while [ $x -le 100 ]
do
if [[ 0 -eq "($x%3) + ($x%5)" ]]
then
# Check if divide by 3 & 5 #
echo "fizz buzz"
elif [[ 0 -eq "($x%5)" ]]
then
# Check if divide by 5 #
echo "buzz"
elif [[ 0 -eq "($x%3)" ]]
then
# Check if divide by 3 #
echo "fizz"
else
echo "$x"
fi
x=$(( $x + 1 ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment