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

(Self Writing)

Date:07/18/12
Author:Olosta
URL:n/a
Comments:0
Info:n/a
Score: (3.00 in 3 votes)
#!/bin/bash
# Clean up previous run
f=$(mktemp scriptXXXX.sh)
head -n 31 $0 > $f
cp -f $f $0
rm $f
# Print verse
bottle=99
if [ $bottle == 1 ] ; then
  str="One bottle"
elif [ $bottle == 0 ] ; then
  str="No more bottles"
else
  str="$bottle bottles"
fi
echo "$str of beer on the wall,"
echo "$str of beer," 
if [ $bottle == 0 ]; then
  echo "Go to the shop and buy some more."
  exit
else
  echo "take one down, pass it around."
fi
# Copy beginning of the file at the end
f=$(mktemp scriptXXXX.sh)
cp -f $0 $f
echo "bottle=$((bottle - 1 ))" >> $f
head -n 30 $0 | tail -n +9 >> $f
cp -f $f $0
rm $f
# New code will go bellow this line

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Bourne Again ShellDave Plonka04/20/055
No loop, no recursionFrédéric Lang07/08/083
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

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: