From: j8takagi Date: Sun, 28 Oct 2012 16:48:40 +0000 (+0900) Subject: シェルスクリプト版を作成 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f09ae747aabf4d4f6bbad3ac047f907ba7044d8;p=fizzbuzz.git シェルスクリプト版を作成 --- diff --git a/sh/fizzbuzz.sh b/sh/fizzbuzz.sh new file mode 100755 index 0000000..2b009c9 --- /dev/null +++ b/sh/fizzbuzz.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +MIN=1 +MAX=100 + +fizzbuzz() { + unset FIZZ; + unset BUZZ; + if test $(expr $1 % 3) -eq 0; then + FIZZ="Fizz"; + fi + if test $(expr $1 % 5) -eq 0; then + BUZZ="Buzz"; + fi + if test -z ${FIZZ} && test -z ${BUZZ}; then + echo $1; + else + echo ${FIZZ}${BUZZ}; + fi +} + +for i in $(seq ${MIN} ${MAX}); do + fizzbuzz $i +done