开发者

Perform action depending on variable value in Batch Files

开发者 https://www.devze.com 2023-03-13 16:37 出处:网络
As the title suggest, how exactly would you do two different action (like below) depending on the value of a variable in a Batch file.

As the title suggest, how exactly would you do two different action (like below) depending on the value of a variable in a Batch file.

E.g.

IF %NUMBER% = 2 do ECHO Number 2
IF %NUMBER% = 1 do ECH开发者_StackOverflow社区O Number 1


Here are two examples

IF "%COMPUTERNAME%" == "Bastie" GOTO :TRUE
REM Insert Code for false
  GOTO NEXT
:TRUE
REM Insert Code for true
  echo Willkommen Zuhause
  REM Jetzt wird der if Zweig verlassen
  GOTO NEXT

:NEXT
echo.Have a nice Day!
  1. Beispiel

    IF "%COMPUTERNAME%" == "Bastie" (
    echo Willkommen zu Hause!
    ) ELSE (
    echo Du bist auf Computer: %COMPUTERNAME%
    )
    


Microsoft has encountered this before. Basically, to fit your scenario:

if %NUMBER% EQU 1 goto number1
if %NUMBER% EQU 2 goto number2
:number1
echo Number 1
:number2
echo Number 2
0

精彩评论

暂无评论...
验证码 换一张
取 消