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> |
||
== |
===AutoHotkey=== |
||
< |
<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</ |
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</ |
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 |
||
}</ |
}</syntaxhighlight> |
||
With a GUI and slight grammatical variation: |
With a GUI and slight grammatical variation: |
||
< |
<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</ |
ExitApp</syntaxhighlight> |
||
Recursive with slight grammatical variation: |
Recursive with slight grammatical variation: |
||
< |
<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 |
||
}</ |
}</syntaxhighlight> |
||
== |
===AutoIt=== |
||
< |
<syntaxhighlight lang="autoit">local $bottleNo=99 |
||
local $lyrics=" " |
local $lyrics=" " |
||
Line 98: | Line 98: | ||
$bottleNo-=1 |
$bottleNo-=1 |
||
WEnd |
WEnd |
||
MsgBox(1,"99",$lyrics)</ |
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> |
|||
== |
===Batch File=== |
||
< |
<syntaxhighlight lang="dos">@echo off |
||
setlocal |
setlocal |
||
:main |
:main |
||
Line 167: | Line 166: | ||
set %2=one |
set %2=one |
||
) |
) |
||
goto :eof</ |
goto :eof</syntaxhighlight> |
||
== |
===friendly interactive shell=== |
||
< |
<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</ |
end</syntaxhighlight> |
||
== |
===PowerShell=== |
||
===A standard impementation using a For loop=== |
====A standard impementation using a For loop==== |
||
< |
<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" |
||
"" |
"" |
||
}</ |
}</syntaxhighlight> |
||
===My standard implementation using for loop=== |
====My standard implementation using for loop==== |
||
< |
<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)</ |
} 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)</ |
} until ($n -eq 0)</syntaxhighlight> |
||
===Consolidating the static text even more=== |
====Consolidating the static text even more==== |
||
< |
<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)</ |
do { $s -f $n, --$n } while ($n -gt 0)</syntaxhighlight> |
||
===Using the Pipeline=== |
====Using the Pipeline==== |
||
< |
<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"}</ |
"$_ 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> |
||
== |
===ProDOS=== |
||
< |
<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</ |
if -b- /hasvalue yes goto :a else exitprogram</syntaxhighlight> |
||
== |
===UNIX Shell=== |
||
{{works with|Bourne Shell}} |
{{works with|Bourne Shell}} |
||
< |
<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</ |
done</syntaxhighlight> |
||
{{works with|Bash}} |
{{works with|Bash}} |
||
{{works with|ksh93}} |
{{works with|ksh93}} |
||
{{works with|zsh}} |
{{works with|zsh}} |
||
< |
<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</ |
done</syntaxhighlight> |
||
=== |
====C Shell==== |
||
⚫ | |||
See [[99 Bottles of Beer/Shell]] |
|||
⚫ | |||
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</ |
end</syntaxhighlight> |
||
=== |
====es==== |
||
es - extensible shell |
es - extensible shell |
||
< |
<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 |
||
}</ |
}</syntaxhighlight> |
||
== |
===UnixPipes=== |
||
< |
<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</ |
rm -rf 99</syntaxhighlight> |