Thread: feedback request [Beginner] Programming Challenge: 1]
well im new here, please kind
found awesome competition, know old want feedback or other alternative bash solutions.
first attempt after reading couple of pages in excellent
other advices on documentation appreciated
code:#!/bin/bash ## # 99 bottles of beer song-generator ## nomorebottles=0 bottles=99 eval bottleary=({$nomorebottles..$bottles}) bottleary[$nomorebottles]="no" n in $(eval echo {$bottles..$nomorebottles}); case $n in [3-99]*) echo ${bottleary[$n]} "bottles of beer on wall," ${bottleary[$n]} "bottles of beer " echo "take on down , pass around," ${bottleary[($n-1)]} "bottles of beer on wall" ;; [2]) echo ${bottleary[$n]} "bottles of beer on wall," ${bottleary[$n]} "bottles of beer " echo "take on down , pass around," ${bottleary[($n-1)]} "bottle of beer on wall" ;; [1]) echo ${bottleary[$n]} "bottle of beer on wall," ${bottleary[$n]} "bottle of beer." echo "take 1 down , pass around," ${bottleary[($n-1)]} "more bottles of beer on wall." ;; [0]) echo ${bottleary[$n]} "more bottles of beer on wall," ${bottleary[$n]} "more bottles of beer." echo "go store , buy more," $bottles "bottles of beer on wall." ;; esac done
hi , welcome forums!
convention, capitalize environment variables (pager, editor, shell, ...) , internal shell variables (bash_version, random, ...). other variable names should contain @ least 1 lowercase letter. remember variable names case-sensitive; convention avoids accidentally overriding environmental , internal variables.
'eval' common misspelling of 'evil'.
see bashfaq 048 , bashfaq 006 (link in signature).
[3-99] equivalent [34567899]. see http://tiswww.case.edu/php/chet/bash/bashref.html#sec36
hth
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk feedback request [Beginner] Programming Challenge: 1]
Ubuntu
Comments
Post a Comment