99 Bottles of Beer/Shell: Difference between revisions

Content added Content deleted
(→‎{{header|UNIX Shell}}: Make bash/ksh/zsh version more idiomatic)
m (Fixed syntax highlighting and duplicate headers.)
 
Line 6: Line 6:
<br><br>
<br><br>


=={{header|AutoHotkey}}==
===AutoHotkey===
<lang AutoHotkey>; RC: 99 bottles of beer
<syntaxhighlight lang="autoHotkey">; RC: 99 bottles of beer
b = 99
b = 99
Loop, %b% {
Loop, %b% {
Line 21: Line 21:
GuiClose:
GuiClose:
ExitApp
ExitApp
Return</lang>
Return</syntaxhighlight>


Delayed Sing along
Delayed Sing along
<syntaxhighlight lang="autoHotkey">n=99
<lang AutoHotkey>n=99
Gui, Font, s20 cMaroon, Comic Sans MS
Gui, Font, s20 cMaroon, Comic Sans MS
Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall...
Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall...
Line 40: Line 40:
}
}
GuiClose:
GuiClose:
ExitApp</lang>
ExitApp</syntaxhighlight>


Fast and Short:
Fast and Short:
<syntaxhighlight lang="autoHotkey">b=99
<lang AutoHotkey>b=99
Loop, %b% {
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"
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: Line 49:
TrayTip,,%s%
TrayTip,,%s%
sleep, 40
sleep, 40
}</lang>
}</syntaxhighlight>


With a GUI and slight grammatical variation:
With a GUI and slight grammatical variation:
<lang AutoHotkey>N=o more
<syntaxhighlight lang="autoHotkey">N=o more
Z=99
Z=99
L:=Z M:=(B:=" bottle")"s"
L:=Z M:=(B:=" bottle")"s"
Line 61: Line 61:
Return
Return
GuiClose:
GuiClose:
ExitApp</lang>
ExitApp</syntaxhighlight>


Recursive with slight grammatical variation:
Recursive with slight grammatical variation:
<lang AutoHotkey>99bottles()
<syntaxhighlight lang="autoHotkey">99bottles()
esc::exitapp
esc::exitapp
Line 75: Line 75:
sleep 99
sleep 99
x?99bottles(x-1):return
x?99bottles(x-1):return
}</lang>
}</syntaxhighlight>


=={{header|AutoIt}}==
===AutoIt===
<lang AutoIt>local $bottleNo=99
<syntaxhighlight lang="autoit">local $bottleNo=99
local $lyrics=" "
local $lyrics=" "


Line 98: Line 98:
$bottleNo-=1
$bottleNo-=1
WEnd
WEnd
MsgBox(1,"99",$lyrics)</lang>
MsgBox(1,"99",$lyrics)</syntaxhighlight>


Easier to read output to Console:
Easier to read output to Console:
<syntaxhighlight lang="autoit">
<lang AutoIt>
$bottles = 99
$bottles = 99
$lyrics1 = " bottles of beer on the wall. "
$lyrics1 = " bottles of beer on the wall. "
Line 116: Line 116:
$bottles -= 1
$bottles -= 1
EndIf
EndIf
Next
Next</syntaxhighlight>
</lang>


=={{header|Batch File}}==
===Batch File===


<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal
setlocal
:main
:main
Line 167: Line 166:
set %2=one
set %2=one
)
)
goto :eof</lang>
goto :eof</syntaxhighlight>


=={{header|friendly interactive shell}}==
===friendly interactive shell===
<lang fishshell>set i 99
<syntaxhighlight lang="fishshell">set i 99
# Assign s to variable $s
# Assign s to variable $s
set s s
set s s
Line 187: Line 186:
echo
echo
end
end
end</lang>
end</syntaxhighlight>


=={{header|PowerShell}}==
===PowerShell===
===A standard impementation using a For loop===
====A standard impementation using a For loop====
<lang PowerShell>for($n=99; $n -gt 0; $n--) {
<syntaxhighlight lang="powershell">for($n=99; $n -gt 0; $n--) {
"$n bottles of beer on the wall"
"$n bottles of beer on the wall"
"$n bottles of beer"
"$n bottles of beer"
Line 197: Line 196:
[string]($n-1) + " bottles of beer on the wall"
[string]($n-1) + " bottles of beer on the wall"
""
""
}</lang>
}</syntaxhighlight>




===My standard implementation using for loop===
====My standard implementation using for loop====
<lang PowerShell>[int]$i = 99;
<syntaxhighlight lang="powershell">[int]$i = 99;
for($i=99; $i -gt 0; $i--) {
for($i=99; $i -gt 0; $i--) {
write-host $i " bottles of beer on the wall";
write-host $i " bottles of beer on the wall";
Line 208: Line 207:
write-host ($i-1) " bottles of beer on the wall"
write-host ($i-1) " bottles of beer on the wall"
write-host ""
write-host ""
}</syntaxhighlight>
}
</lang>


===Consolidating the static text and using a Do...while loop===
====Consolidating the static text and using a Do...while loop====
<syntaxhighlight lang="powershell">$n=99
<lang PowerShell>$n=99
do {
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
"{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)</lang>
} while ($n -gt 0)</syntaxhighlight>


===Consolidating the static text and using a Do...until loop===
====Consolidating the static text and using a Do...until loop====
<syntaxhighlight lang="powershell">$n=99
<lang PowerShell>$n=99
do {
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
"{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)</lang>
} until ($n -eq 0)</syntaxhighlight>




===Consolidating the static text even more===
====Consolidating the static text even more====
<lang 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"
<syntaxhighlight lang="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
$n=99
do { $s -f $n, --$n } while ($n -gt 0)</lang>
do { $s -f $n, --$n } while ($n -gt 0)</syntaxhighlight>


===Using the Pipeline===
====Using the Pipeline====
<lang Powershell>99..1 | ForEach-Object {
<syntaxhighlight lang="powershell">99..1 | ForEach-Object {
$s=$( if( $_ -ne 1 ) { 's' } else { '' } )
$s=$( if( $_ -ne 1 ) { 's' } else { '' } )
$s2=$( if( $_ -ne 2 ) { '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"}</lang>
"$_ 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"}</syntaxhighlight>



=={{header|ProDOS}}==
===ProDOS===
<lang ProDOS>editvar /newvar /value=a=99
<syntaxhighlight lang="prodos">editvar /newvar /value=a=99
:a
:a
printline -a- bottles of beer on the wall
printline -a- bottles of beer on the wall
Line 252: Line 249:
printline no bottles of beer on the wall.
printline no bottles of beer on the wall.
editvar /newvar /value=b /userinput=1 /title=Keep drinking?
editvar /newvar /value=b /userinput=1 /title=Keep drinking?
if -b- /hasvalue yes goto :a else exitprogram</lang>
if -b- /hasvalue yes goto :a else exitprogram</syntaxhighlight>


=={{header|UNIX Shell}}==
===UNIX Shell===
{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<lang bash>#!/bin/sh
<syntaxhighlight lang="bash">#!/bin/sh


i=99 s=s
i=99 s=s
Line 269: Line 266:
echo "$i bottle$s of beer on the wall
echo "$i bottle$s of beer on the wall
"
"
done</lang>
done</syntaxhighlight>


{{works with|Bash}}
{{works with|Bash}}
{{works with|ksh93}}
{{works with|ksh93}}
{{works with|zsh}}
{{works with|zsh}}
<lang bash>bottles() {
<syntaxhighlight lang="bash">bottles() {
beer=$1
beer=$1
(( beer > 0 )) && printf '%d' $beer || printf "No more"
(( beer > 0 )) && printf '%d' $beer || printf "No more"
Line 294: Line 291:
fi
fi
printf '%s on the wall\n\n' "$(bottles $remaining)"
printf '%s on the wall\n\n' "$(bottles $remaining)"
done</lang>
done</syntaxhighlight>


==={{header|C Shell}}===
====C Shell====
<syntaxhighlight lang="csh">@ i=99
See [[99 Bottles of Beer/Shell]]
<lang csh>@ i=99
set s=s
set s=s
while ($i > 0)
while ($i > 0)
Line 312: Line 308:
echo "$i bottle$s of beer on the wall"
echo "$i bottle$s of beer on the wall"
echo ""
echo ""
end</lang>
end</syntaxhighlight>


==={{header|es}}===
====es====
es - extensible shell
es - extensible shell


<lang es>i = 99
<syntaxhighlight lang="es">i = 99
s = s
s = s
while {test $i -gt 0} {
while {test $i -gt 0} {
Line 327: Line 323:
echo $i bottle$s of beer on the wall
echo $i bottle$s of beer on the wall
echo
echo
}</lang>
}</syntaxhighlight>


=={{header|UnixPipes}}==
===UnixPipes===
<lang bash># Unix Pipes, avoiding all the turing complete sub programs like sed, awk, dc etc.
<syntaxhighlight lang="bash"># Unix Pipes, avoiding all the turing complete sub programs like sed, awk, dc etc.
mkdir 99 || exit 1
mkdir 99 || exit 1
trap "rm -rf 99" 1 2 3 4 5 6 7 8
trap "rm -rf 99" 1 2 3 4 5 6 7 8
Line 344: Line 340:
cat p.b2 | tail -99 | paste -d"\ " p.verse1 - p.wall | head -n 99
cat p.b2 | tail -99 | paste -d"\ " p.verse1 - p.wall | head -n 99
)
)
rm -rf 99</lang>
rm -rf 99</syntaxhighlight>