Blogger

Windows Dos Batch Files


@echo off

IF .%1 == . (
GOTO ERROR
) ELSE IF .%1 == .goat (
SET MSG=echo good guess
) ELSE (
SET MSG=echo nope %1 is wrong
)

IF .%2 == . (
GOTO ACTION
) ELSE IF .%2 == .goat (
SET MSG=%MSG% ^& echo good guess
) ELSE (
SET MSG=%MSG% ^& echo nope %2 is wrong
)

IF NOT .%3 == . ( GOTO ERROR )

:ACTION
echo.
echo Thanks for playing.
%MSG%
GOTO DONE

:ERROR
echo.
echo doit ^<guess^> [^<another^>]
echo.
echo Example: doit mouse
echo.

:DONE

You don't need quotes. But in order to check for empty vars you can prefix with anything, for example a dot. You get the args via %1, %2, etc. You set vars using anyname and later read them via %anyname%. You can mimic functions via GOTO. Special characters like <>& need to be escaped via ^ in order to be printed. You can print an empty line via echo followed by a dot, but you can't embed a line break in an echo. You can build a var that is a series of echo commands separated via the & symbol (which indicates that a new command is starting).

 |  Tribal Worker  |  Terms  |  Aggressive Software  |  Feedback  |