-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz
More file actions
executable file
·47 lines (37 loc) · 984 Bytes
/
fizzbuzz
File metadata and controls
executable file
·47 lines (37 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
#
set -e
BREAK_AGAIN=
fizzbuzz () {
local n
for n in {1..100}; do
{ (( n % 15 == 0 )) && echo 'FizzBuzz'; } ||
{ (( n % 5 == 0 )) && echo 'Buzz' ; } ||
{ (( n % 3 == 0 )) && echo 'Fizz' ; } ||
echo "$n"
done
}
main () {
echo "Running and debugging $0 ..."
echo "Starting a pipeline to compute fizzbuzz and totals..."
fizzbuzz \
|
(declare -A totals=()
while read -r line; do
echo "$line"
if [[ $line != [0-9]* ]]; then
(( ++totals[$line] ))
fi
done
# we'll have the second break point here if BREAK_AGAIN is set to non-empty
[[ ! ${BREAK_AGAIN:-} ]] || source tbd.sh
echo
printf "There are %d Fizz, %d Buzz, and %d FizzBuzz!\n" \
"${totals[Fizz]:-0}" \
"${totals[Buzz]:-0}" \
"${totals[FizzBuzz]:-0}"
)
echo "--- The End ---"
}
source tbd.sh # first break point
main "$@"