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

(Bourne Again Shell)

Date:04/20/05
Author:Dave Plonka
URL:n/a
Comments:5
Info:n/a
Score: (3.00 in 55 votes)
#!/bin/bash
# Bourne Again shell version of 99 Bottles
# Dave Plonka - plonka@carroll1.cc.edu

typeset -i n=99
typeset bottles=bottles
typeset no

while [ 0 != $[ n ] ]
do
   echo "${n?} ${bottles?} of beer on the wall,"
   echo "${n?} ${bottles?} of beer,"
   echo "take one down, pass it around,"
   n=n-1
   case ${n?} in
   0)
      no=no
      bottles=${bottles%s}s
      ;;
   1)
      bottles=${bottles%s}
      ;;
   esac
   echo "${no:-${n}} ${bottles?} of beer on the wall."
   echo
done

exit

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
No loop, no recursionFrédéric Lang07/08/083
Self WritingOlosta07/18/120
portable, rich of features, readableBastian Bittorf08/20/070
with arrays and functionsVittorio Cagnetta06/30/060
Arithmetic on English words for numbersBill Brown07/31/080
recursive functionKoen Noens12/30/070

Comments

>>  Marcus said on 05/19/06 09:33:36

Marcus Simple, Smart - Bash! ;-)
I like it.

>>  David said on 04/23/08 02:22:51

David here is what i did on a command line on a linux box with bash a few standard commands

for x in `seq -99 -1| sed s/-//`;do echo $x bottles of beer on the wall, $x bottles of beer, take one down, pass it around... $x bottles of beer on the wall;done

>>  Samus Aran said on 03/09/10 03:55:52

Samus Aran @David:
Why in the world would you do that rather than just:

for x in {99..1}; do ...; done

>>  Samus Aran said on 03/09/10 03:57:55

Samus Aran Or alternatively:

for (x=99; x>0; x++); do ...; done

>>  Samus Aran said on 03/09/10 03:59:08

Samus Aran They need an edit comment feature on this site. :P Or at least a preview before posting.

Anyhow, x-- not x++. Oops.

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: