Language BASH
(No loop, no recursion)
| Date: | 07/08/08 |
| Author: | Frédéric Lang |
| URL: | http://fr.lang.free.fr |
| Comments: | 3 |
| Info: | http://fr.lang.free.fr/cours |
| Score: |
#!/bin/bash
#
# Bourne Again shell version of 99 Bottles - No loop - No recursion
# By Frédéric Lang (http://fr.lang.free.fr)
# Memorize count initial
max=${max:-99}
# Store count actual
typeset -i count=${next:-$max}
# Calculate next count
typeset -i next=count-1
# Evaluate count
if test $count -gt 0
then
middle="take one down, pass it around"
case $count in
1)
first="one bottle"
last="no more bottles"
;;
2)
first="2 bottles"
last="one bottle"
;;
*)
first="$count bottles"
last="$next bottles"
esac
order="source $0"
else
# Last occur
first="no more bottles"
middle="go to the shop and buy some more"
last="$max bottles"
order="exit 0"
fi
# Print sing
echo "$first of beer on the wall,"
echo "$first of beer,"
echo "$middle,"
echo "$last of beer on the wall."
echo
# Next occur
$order
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Bourne Again Shell | Dave Plonka | 04/20/05 | 5 | |
| Self Writing | Olosta | 07/18/12 | 0 | |
| portable, rich of features, readable | Bastian Bittorf | 08/20/07 | 0 | |
| with arrays and functions | Vittorio Cagnetta | 06/30/06 | 0 | |
| Arithmetic on English words for numbers | Bill Brown | 07/31/08 | 0 | |
| recursive function | Koen Noens | 12/30/07 | 0 |
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!
Comments
My question is: could be the result the same even if you don't source the script, but simply re-launch it ( that is, order="eval $0" )? In my humble opinion yes, the result is the same, because sourcing a text executable that has in first row: "#![INTERPRETER-PATH]", is like launching it.
Anyway, your script is nice.