99 Bottles of Beer/Shell: Difference between revisions

m
Fixed syntax highlighting and duplicate headers.
(→‎{{header|UNIX Shell}}: Make bash/ksh/zsh version more idiomatic)
m (Fixed syntax highlighting and duplicate headers.)
 
Line 6:
<br><br>
 
=={{header|=AutoHotkey}}===
<langsyntaxhighlight AutoHotkeylang="autoHotkey">; RC: 99 bottles of beer
b = 99
Loop, %b% {
Line 21:
GuiClose:
ExitApp
Return</langsyntaxhighlight>
 
Delayed Sing along
<syntaxhighlight lang="autoHotkey">n=99
<lang AutoHotkey>n=99
Gui, Font, s20 cMaroon, Comic Sans MS
Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall...
Line 40:
}
GuiClose:
ExitApp</langsyntaxhighlight>
 
Fast and Short:
<syntaxhighlight lang="autoHotkey">b=99
<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 49:
TrayTip,,%s%
sleep, 40
}</langsyntaxhighlight>
 
With a GUI and slight grammatical variation:
<langsyntaxhighlight AutoHotkeylang="autoHotkey">N=o more
Z=99
L:=Z M:=(B:=" bottle")"s"
Line 61:
Return
GuiClose:
ExitApp</langsyntaxhighlight>
 
Recursive with slight grammatical variation:
<langsyntaxhighlight AutoHotkeylang="autoHotkey">99bottles()
esc::exitapp
Line 75:
sleep 99
x?99bottles(x-1):return
}</langsyntaxhighlight>
 
=={{header|=AutoIt}}===
<langsyntaxhighlight AutoItlang="autoit">local $bottleNo=99
local $lyrics=" "
 
Line 98:
$bottleNo-=1
WEnd
MsgBox(1,"99",$lyrics)</langsyntaxhighlight>
 
Easier to read output to Console:
<syntaxhighlight lang="autoit">
<lang AutoIt>
$bottles = 99
$lyrics1 = " bottles of beer on the wall. "
Line 116:
$bottles -= 1
EndIf
Next</syntaxhighlight>
</lang>
 
=={{header|=Batch File}}===
 
<langsyntaxhighlight lang="dos">@echo off
setlocal
:main
Line 167 ⟶ 166:
set %2=one
)
goto :eof</langsyntaxhighlight>
 
=={{header|=friendly interactive shell}}===
<langsyntaxhighlight lang="fishshell">set i 99
# Assign s to variable $s
set s s
Line 187 ⟶ 186:
echo
end
end</langsyntaxhighlight>
 
=={{header|=PowerShell}}===
====A standard impementation using a For loop====
<langsyntaxhighlight PowerShelllang="powershell">for($n=99; $n -gt 0; $n--) {
"$n bottles of beer on the wall"
"$n bottles of beer"
Line 197 ⟶ 196:
[string]($n-1) + " bottles of beer on the wall"
""
}</langsyntaxhighlight>
 
 
====My standard implementation using for loop====
<langsyntaxhighlight PowerShelllang="powershell">[int]$i = 99;
for($i=99; $i -gt 0; $i--) {
write-host $i " bottles of beer on the wall";
Line 208 ⟶ 207:
write-host ($i-1) " bottles of beer on the wall"
write-host ""
}</syntaxhighlight>
}
</lang>
 
====Consolidating the static text and using a Do...while loop====
<syntaxhighlight lang="powershell">$n=99
<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)</langsyntaxhighlight>
 
====Consolidating the static text and using a Do...until loop====
<syntaxhighlight lang="powershell">$n=99
<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)</langsyntaxhighlight>
 
 
====Consolidating the static text even more====
<langsyntaxhighlight PowerShelllang="powershell">$s = "{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"
$n=99
do { $s -f $n, --$n } while ($n -gt 0)</langsyntaxhighlight>
 
====Using the Pipeline====
<langsyntaxhighlight Powershelllang="powershell">99..1 | ForEach-Object {
$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"}</langsyntaxhighlight>
 
 
=={{header|=ProDOS}}===
<langsyntaxhighlight ProDOSlang="prodos">editvar /newvar /value=a=99
:a
printline -a- bottles of beer on the wall
Line 252 ⟶ 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</langsyntaxhighlight>
 
=={{header|=UNIX Shell}}===
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">#!/bin/sh
 
i=99 s=s
Line 269 ⟶ 266:
echo "$i bottle$s of beer on the wall
"
done</langsyntaxhighlight>
 
{{works with|Bash}}
{{works with|ksh93}}
{{works with|zsh}}
<langsyntaxhighlight lang="bash">bottles() {
beer=$1
(( beer > 0 )) && printf '%d' $beer || printf "No more"
Line 294 ⟶ 291:
fi
printf '%s on the wall\n\n' "$(bottles $remaining)"
done</langsyntaxhighlight>
 
==={{header|=C Shell}}====
<langsyntaxhighlight lang="csh">@ i=99
See [[99 Bottles of Beer/Shell]]
<lang csh>@ i=99
set s=s
while ($i > 0)
Line 312 ⟶ 308:
echo "$i bottle$s of beer on the wall"
echo ""
end</langsyntaxhighlight>
 
==={{header|=es}}====
es - extensible shell
 
<langsyntaxhighlight lang="es">i = 99
s = s
while {test $i -gt 0} {
Line 327 ⟶ 323:
echo $i bottle$s of beer on the wall
echo
}</langsyntaxhighlight>
 
=={{header|=UnixPipes}}===
<langsyntaxhighlight lang="bash"># Unix Pipes, avoiding all the turing complete sub programs like sed, awk, dc etc.
mkdir 99 || exit 1
trap "rm -rf 99" 1 2 3 4 5 6 7 8
Line 344 ⟶ 340:
cat p.b2 | tail -99 | paste -d"\ " p.verse1 - p.wall | head -n 99
)
rm -rf 99</langsyntaxhighlight>
9,485

edits