99 Bottles of Beer/Shell: Difference between revisions
Content added Content deleted
(→{{header|UNIX Shell}}: Make bash/ksh/zsh version more idiomatic) |
|||
Line 276: | Line 276: | ||
<lang bash>bottles() { |
<lang bash>bottles() { |
||
beer=$1 |
beer=$1 |
||
(( beer > 0 )) && printf '%d' $beer || printf "No more" |
|||
printf " bottle" |
|||
((beer != 1 )) && printf "s" |
|||
printf " of beer" |
|||
} |
} |
||
for ((i=99;i>=0;i--)); do |
for ((i=99;i>=0;i--)); do |
||
((remaining=i)) |
((remaining=i)) |
||
printf '%s on the wall\n' "$(bottles $remaining)" |
|||
printf '%s\n' "$(bottles $remaining)" |
|||
if |
if (( remaining == 0 )); then |
||
printf 'Go to the store and buy some more\n' |
|||
((remaining+=99)) |
((remaining+=99)) |
||
else |
else |
||
printf 'Take one down, pass it around\n' |
|||
((remaining--)) |
((remaining--)) |
||
fi |
fi |
||
printf '%s on the wall\n\n' "$(bottles $remaining)" |
|||
echo |
|||
done</lang> |
done</lang> |
||