Skip to content

Instantly share code, notes, and snippets.

@stevenwilkin
Created January 5, 2017 15:00
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 stevenwilkin/20c9a7f3c5e4a554aaebf7690df2d177 to your computer and use it in GitHub Desktop.
Save stevenwilkin/20c9a7f3c5e4a554aaebf7690df2d177 to your computer and use it in GitHub Desktop.
FizzBuzz in Bash
#!/bin/bash
set -u
for i in $(seq 1 20); do
divisible_by_three=$(expr $i % 3)
divisible_by_five=$(expr $i % 5)
[ $divisible_by_three -eq 0 ] && [ $divisible_by_five -eq 0 ] && echo "Fizz Buzz" && continue
[ $divisible_by_three -eq 0 ] && echo "Fizz" && continue
[ $divisible_by_five -eq 0 ] && echo "Buzz" && continue
echo $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment