Created
October 7, 2017 04:05
-
-
Save dexterous/15be43f02fa2a134c120aec187509ab3 to your computer and use it in GitHub Desktop.
A succinct bash fizzbuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
#set -o xtrace | |
if [[ $# -lt 1 ]]; then | |
echo ' | |
Usage: fizzbuzz upto | |
upto: The number upto which to count | |
' | |
exit 1 | |
fi | |
for x in $(seq 1 "${1}"); do | |
RESULT='' | |
if [[ $((x % 3)) -eq 0 ]]; then | |
RESULT="${RESULT}Fizz" | |
fi | |
if [[ $((x % 5)) -eq 0 ]]; then | |
RESULT="${RESULT}Buzz" | |
fi | |
echo "${RESULT:-${x}}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute like so:
./fizzbuzz 100 | cat -n