Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 86 characters, minimal spaces.
- for i in {1..100};do printf "\n$i\r";(($i%3))||printf Fizz;(($i%5))||printf Buzz;done
- # loop over the numbers
- for i in {1..100};
- do
- printf "\n$i\r"; #newline, number, cariage return (back to beginning of line)
- # if devisible by 3, print fizz, this will overwrite the number since we're back at the start of the line.
- # if devisible by 3 (($i%3)) returns 0, which is false, so we use the "or" operator, not "and"
- # use printf here since we don't want a newline and 'echo -n' is longer then printf
- (($i%3))||printf Fizz;
- # same for 5
- (($i%5))||printf Buzz;
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement