Batch - If, ElseIf, Else
Answer :
@echo off title Test echo Select a language. (de/en) set /p language= IF /i "%language%"=="de" goto languageDE IF /i "%language%"=="en" goto languageEN echo Not found. goto commonexit :languageDE echo German goto commonexit :languageEN echo English goto commonexit :commonexit pause
The point is that batch simply continues through instructions, line by line until it reaches a goto
, exit
or end-of-file. It has no concept of sections
to control flow.
Hence, entering de
would jump to :languagede
then simply continue executing instructions until the file ends, showing de
then en
then not found
.
@echo off set "language=de" IF "%language%" == "de" ( goto languageDE ) ELSE ( IF "%language%" == "en" ( goto languageEN ) ELSE ( echo Not found. ) ) :languageEN :languageDE echo %language%
This works , but not sure how your language variable is defined.Does it have spaces in its definition.
batchfiles perform simple string substitution with variables. so, a simple
goto :language%language% echo notfound ...
does this without any need for if.
Comments
Post a Comment