99 Bottles of Beer/Shell: Difference between revisions
m (moving code from main task-page to sub-page) |
(AutoHotkey) |
||
Line 1: | Line 1: | ||
=Task in Shell(s)= |
<!-- =Task in Shell(s)= --> |
||
{{collection|99 Bottles of Beer}} [[implementation of task::99 Bottles of Beer| ]] |
{{collection|99 Bottles of Beer}} [[implementation of task::99 Bottles of Beer| ]] |
||
[[99 Bottles of Beer]] done in any of the Shell-languages. |
[[99 Bottles of Beer]] done in any of the Shell-languages. |
||
__toc__ |
__toc__ |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>; RC: 99 bottles of beer |
|||
b = 99 |
|||
Loop, %b% { |
|||
s .= b . " bottles of beer on the wall,`n" |
|||
. b . " bottles of beer.`nTake one down, pass it around,`n" |
|||
. b-1 . " bottles of beer on the wall.`n`n" |
|||
b-- |
|||
} |
|||
Gui, Add, Edit, w200 h200, %s% |
|||
Gui, Show, , 99 bottles of beer |
|||
Return ; end of auto-execute section |
|||
GuiClose: |
|||
ExitApp |
|||
Return</lang> |
|||
Delayed Sing along |
|||
<lang AutoHotkey>n=99 |
|||
Gui, Font, s20 cMaroon, Comic Sans MS |
|||
Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall... |
|||
Gui, Show |
|||
Loop { |
|||
Sleep, 2000 |
|||
GuiControl,,Lyrics,% n!=1 ? n " bottles of beer.":n " bottle of beer." |
|||
Sleep, 2000 |
|||
GuiControl,,Lyrics,% n ? "Take one down, pass it around...":"Go to the store, buy some more..." |
|||
Sleep, 2000 |
|||
n := n ? --n:99 |
|||
GuiControl,,Lyrics,% n!=1 ? n " bottles of beer on the wall.":n " bottle of beer on the wall." |
|||
Sleep, 2000 |
|||
GuiControl,,Lyrics,% n!=1 ? n " bottles of beer on the wall...":n " bottle of beer on the wall..." |
|||
} |
|||
GuiClose: |
|||
ExitApp</lang> |
|||
Fast and Short |
|||
<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" |
|||
b-- |
|||
TrayTip,,%s% |
|||
sleep, 40 |
|||
}</lang> |
|||
With a GUI and slight grammatical variation: |
|||
<lang AutoHotkey>N=o more |
|||
Z=99 |
|||
L:=Z M:=(B:=" bottle")"s" |
|||
Loop 99 |
|||
V.=L (W:=(O:=" of beer")" on the wall")",`n"L O ",`nTake one down and pass it around,`n"(L:=(--Z ? Z:"N"N)(Z=1 ? B:M))W ".`n`n" |
|||
Gui,Add,Edit,w600 h250,% V L W ", n"N M O ".`nGo to the store and buy some more, 99"M W "." |
|||
Gui,Show |
|||
Return |
|||
GuiClose: |
|||
ExitApp</lang> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
Revision as of 04:13, 21 November 2014
99 Bottles of Beer done in any of the Shell-languages.
AutoHotkey
<lang AutoHotkey>; RC: 99 bottles of beer
b = 99 Loop, %b% { s .= b . " bottles of beer on the wall,`n" . b . " bottles of beer.`nTake one down, pass it around,`n" . b-1 . " bottles of beer on the wall.`n`n" b-- } Gui, Add, Edit, w200 h200, %s% Gui, Show, , 99 bottles of beer
Return ; end of auto-execute section
GuiClose:
ExitApp
Return</lang>
Delayed Sing along <lang AutoHotkey>n=99 Gui, Font, s20 cMaroon, Comic Sans MS Gui, Add, Text, w500 vLyrics, %n% bottles of beer on the wall... Gui, Show Loop {
Sleep, 2000 GuiControl,,Lyrics,% n!=1 ? n " bottles of beer.":n " bottle of beer." Sleep, 2000 GuiControl,,Lyrics,% n ? "Take one down, pass it around...":"Go to the store, buy some more..." Sleep, 2000 n := n ? --n:99 GuiControl,,Lyrics,% n!=1 ? n " bottles of beer on the wall.":n " bottle of beer on the wall." Sleep, 2000 GuiControl,,Lyrics,% n!=1 ? n " bottles of beer on the wall...":n " bottle of beer on the wall..."
} GuiClose: ExitApp</lang>
Fast and Short <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" b-- TrayTip,,%s% sleep, 40 }</lang>
With a GUI and slight grammatical variation: <lang AutoHotkey>N=o more Z=99 L:=Z M:=(B:=" bottle")"s" Loop 99 V.=L (W:=(O:=" of beer")" on the wall")",`n"L O ",`nTake one down and pass it around,`n"(L:=(--Z ? Z:"N"N)(Z=1 ? B:M))W ".`n`n" Gui,Add,Edit,w600 h250,% V L W ", n"N M O ".`nGo to the store and buy some more, 99"M W "." Gui,Show Return GuiClose: ExitApp</lang>
Batch File
<lang dos>@echo off setlocal
- main
for /L %%i in (99,-1,1) do ( call :verse %%i ) echo no bottles of beer on the wall echo no bottles of beer echo go to the store and buy some more echo 99 bottles of beer on the wall echo. set /p q="Keep drinking? " if %q% == y goto main if %q% == Y goto main goto :eof
- verse
call :plural %1 res echo %res% of beer on the wall echo %res% of beer call :oneit %1 res echo take %res% down and pass it round set /a c=%1-1 call :plural %c% res echo %res% of beer on the wall echo. goto :eof
- plural
if %1 gtr 1 goto :gtr if %1 equ 1 goto :equ set %2=no bottles goto :eof
- gtr
set %2=%1 bottles goto :eof
- equ
set %2=1 bottle goto :eof
- oneit
if %1 equ 1 ( set %2=it ) else ( set %2=one ) goto :eof</lang>
friendly interactive shell
<lang fishshell>set i 99
- Assign s to variable $s
set s s while test $i != 'No more'
echo $i bottle$s of beer on the wall, echo $i bottle$s of beer. echo Take one down, pass it around, set i (math $i - 1) if test $i -eq 1 set s "" else if test $i -eq 0 set i 'No more' end echo $i bottle$s of beer on the wall. if test $i != 'No more' echo end
end</lang>
UNIX Shell
<lang bash>#!/bin/sh
i=99 s=s
while [ $i -gt 0 ]; do
echo "$i bottle$s of beer on the wall" echo "$i bottle$s of beer
Take one down, pass it around"
# POSIX allows for $(( i - 1 )) but some older Unices didn't have that i=`expr $i - 1`
[ $i -eq 1 ] && s= || s=s
echo "$i bottle$s of beer on the wall
" done</lang>
<lang bash>bottles() {
beer=$1 [ $((beer)) -gt 0 ] && echo -n $beer || echo -n "No more" echo -n " bottle" [ $((beer)) -ne 1 ] && echo -n "s" echo -n " of beer"
}
for ((i=99;i>=0;i--)); do
((remaining=i)) echo "$(bottles $remaining) on the wall" echo "$(bottles $remaining)" if [ $((remaining)) -eq 0 ]; then echo "Go to the store and buy some more" ((remaining+=99)) else echo "Take one down, pass it around" ((remaining--)) fi echo "$(bottles $remaining) on the wall" echo
done</lang>
C Shell
See 99 Bottles of Beer/Shell <lang csh>@ i=99 set s=s while ($i > 0) echo "$i bottle$s of beer on the wall" echo "$i bottle$s of beer" echo "Take one down, pass it around" @ i = $i - 1 if ($i == 1) then set s= else set s=s endif echo "$i bottle$s of beer on the wall" echo "" end</lang>