Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language bash

(with arrays and functions)

Date:06/30/06
Author:Vittorio Cagnetta
URL:n/a
Comments:0
Info:http://www.gnu.org/software/bash/
Score: (2.82 in 11 votes)
#!/bin/bash
# Bourne Again shell version (yet another) of 99 Bottles
# Vittorio Cagnetta - vaisarger@yahoo.it

strophe()
	{
	echo "\
${n} ${bottles[0]} of beer on the wall,
${n} ${bottles[0]} of beer,
take one down, pass it around,
${N} ${bottles[1]} of beer on the wall.
"
}

bottles=( [0]=bottles [1]=bottles )

for (( n=99,N=98 ; n>0 ; n--,N-- )); do
	if [ ${N} -eq 1 ]; then
		bottles[1]=bottle
	elif [ ${N} -eq 0 ]; then
		bottles=( [0]=bottle [1]=bottles ) && N=no
	fi
	strophe
done

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Bourne Again ShellDave Plonka04/20/055
No loop, no recursionFrédéric Lang07/08/083
Self WritingOlosta07/18/120
portable, rich of features, readableBastian Bittorf08/20/070
Arithmetic on English words for numbersBill Brown07/31/080
recursive functionKoen Noens12/30/070

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: