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)) -gt 0 ] && echo -n $beer || echo -n "No more"
(( beer > 0 )) && printf '%d' $beer || printf "No more"
echo -n " bottle"
printf " bottle"
[ $((beer)) -ne 1 ] && echo -n "s"
((beer != 1 )) && printf "s"
echo -n " of beer"
printf " of beer"
}
}


for ((i=99;i>=0;i--)); do
for ((i=99;i>=0;i--)); do
((remaining=i))
((remaining=i))
echo "$(bottles $remaining) on the wall"
printf '%s on the wall\n' "$(bottles $remaining)"
echo "$(bottles $remaining)"
printf '%s\n' "$(bottles $remaining)"
if [ $((remaining)) -eq 0 ]; then
if (( remaining == 0 )); then
echo "Go to the store and buy some more"
printf 'Go to the store and buy some more\n'
((remaining+=99))
((remaining+=99))
else
else
echo "Take one down, pass it around"
printf 'Take one down, pass it around\n'
((remaining--))
((remaining--))
fi
fi
echo "$(bottles $remaining) on the wall"
printf '%s on the wall\n\n' "$(bottles $remaining)"
echo
done</lang>
done</lang>