99 Bottles of Beer/Shell: Difference between revisions
m
Fixed syntax highlighting and duplicate headers.
(→{{header|UNIX Shell}}: The "s=s" assignment is superfluous since the loop ends once s gets emptied.) |
m (Fixed syntax highlighting and duplicate headers.) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1:
<!-- =Task in Shell(s)= -->
{{collection|99 Bottles of Beer}}
[[implementation of task::99 Bottles of Beer| ]]
[[99 Bottles of Beer]] done in any of the Shell-languages.
<br><br>
==
<
b = 99
Loop, %b% {
Line 19 ⟶ 21:
GuiClose:
ExitApp
Return</
Delayed Sing along
<syntaxhighlight lang="autoHotkey">n=99
Gui, Font, s20 cMaroon, Comic Sans MS
Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall...
Line 38 ⟶ 40:
}
GuiClose:
ExitApp</
Fast and Short:
<syntaxhighlight lang="autoHotkey">b=99
Loop, %b% {
s := b " bottles of beer on the wall, " b " bottles of beer, Take one down, pass it around " b-1 " bottles of beer on the wall"
Line 47 ⟶ 49:
TrayTip,,%s%
sleep, 40
}</
With a GUI and slight grammatical variation:
<
Z=99
L:=Z M:=(B:=" bottle")"s"
Line 59 ⟶ 61:
Return
GuiClose:
ExitApp</
Recursive with slight grammatical variation:
=={{header|AutoIt}}==▼
<syntaxhighlight lang="autoHotkey">99bottles()
<lang AutoIt>local $bottleNo=99▼
esc::exitapp
99bottles(x=99) {
ToolTip, % Format("{1:} {2:} of beer on the wall, {1:L} {2:} of beer.{4:}{3:} {2:} of beer on the wall!"
,(x?x:"No more")
,(x=1?"bottle":"bottles")
,(x=1?"no more":x=0?99:x-1)
,(x?"`nYou take one down pass it around, ":"`nGo to the store and buy some more, ")),500,300
sleep 99
x?99bottles(x-1):return
}</syntaxhighlight>
local $lyrics=" "
Line 82 ⟶ 98:
$bottleNo-=1
WEnd
MsgBox(1,"99",$lyrics)</
Easier to read output to Console:
<syntaxhighlight lang="autoit">
$bottles = 99
$lyrics1 = " bottles of beer on the wall. "
Line 100 ⟶ 116:
$bottles -= 1
EndIf
Next</syntaxhighlight>
==
<
setlocal
:main
Line 151 ⟶ 166:
set %2=one
)
goto :eof</
==
<
# Assign s to variable $s
set s s
Line 171 ⟶ 186:
echo
end
end</
==
====A standard impementation using a For loop====
<
"$n bottles of beer on the wall"
"$n bottles of beer"
Line 181 ⟶ 196:
[string]($n-1) + " bottles of beer on the wall"
""
}</
====My standard implementation using for loop====
<
for($i=99; $i -gt 0; $i--) {
write-host $i " bottles of beer on the wall";
Line 192 ⟶ 207:
write-host ($i-1) " bottles of beer on the wall"
write-host ""
}</syntaxhighlight>
====Consolidating the static text and using a Do...while loop====
<syntaxhighlight lang="powershell">$n=99
do {
"{0} bottles of beer on the wall`n{0} bottles of beer`nTake one down, pass it around`n{1} bottles of beer on the wall`n" -f $n, --$n
} while ($n -gt 0)</
====Consolidating the static text and using a Do...until loop====
<syntaxhighlight lang="powershell">$n=99
do {
"{0} bottles of beer on the wall`n{0} bottles of beer`nTake one down, pass it around`n{1} bottles of beer on the wall`n" -f $n, --$n
} until ($n -eq 0)</
====Consolidating the static text even more====
<
$n=99
do { $s -f $n, --$n } while ($n -gt 0)</
====Using the Pipeline====
<
$s=$( if( $_ -ne 1 ) { 's' } else { '' } )
$s2=$( if( $_ -ne 2 ) { 's' } else { '' } )
"$_ bottle$s of beer on the wall`n$_ bottle$s of beer`nTake one down`npass it around`n$( $_ - 1 ) bottle$s2 of beer on the wall`n"}</
==
<
:a
printline -a- bottles of beer on the wall
Line 236 ⟶ 249:
printline no bottles of beer on the wall.
editvar /newvar /value=b /userinput=1 /title=Keep drinking?
if -b- /hasvalue yes goto :a else exitprogram</
==
{{works with|Bourne Shell}}
<
i=99 s=s
Line 253 ⟶ 266:
echo "$i bottle$s of beer on the wall
"
done</
{{works with|Bash}}
{{works with|ksh93}}
{{works with|zsh}}
<
beer=$1
}
for ((i=99;i>=0;i--)); do
((remaining=i))
if
((remaining+=99))
else
((remaining--))
fi
done</syntaxhighlight>
===
▲<lang csh>@ i=99
set s=s
while ($i > 0)
Line 297 ⟶ 308:
echo "$i bottle$s of beer on the wall"
echo ""
end</
===
es - extensible shell
<
s = s
while {test $i -gt 0} {
Line 312 ⟶ 323:
echo $i bottle$s of beer on the wall
echo
}</
==
<
mkdir 99 || exit 1
trap "rm -rf 99" 1 2 3 4 5 6 7 8
Line 329 ⟶ 340:
cat p.b2 | tail -99 | paste -d"\ " p.verse1 - p.wall | head -n 99
)
rm -rf 99</
|