windows 根据批处理文件中的变量值执行操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6360142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:03:53 来源:igfitidea点击:
Perform action depending on variable value in Batch Files
提问by Dennis
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 ECHO Number 1
回答by Dukeatcoding
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!
Beispiel
IF "%COMPUTERNAME%" == "Bastie" ( echo Willkommen zu Hause! ) ELSE ( echo Du bist auf Computer: %COMPUTERNAME% )
贝斯皮尔
IF "%COMPUTERNAME%" == "Bastie" ( echo Willkommen zu Hause! ) ELSE ( echo Du bist auf Computer: %COMPUTERNAME% )
回答by dolphy
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