批处理脚本冒险
这是我的批处理脚本文件。有两种情况
- 情况 1
@echo off
set name=
set /P TypeName=Name: %=%
if %TypeName% == "abcd" goto correctName
else goto wrongName
:correctName
echo Correct Name
:end
:wrongName
echo Wrong Name
:end
当我输入 abcd 作为输入时,我得到 'else' 未被识别为内部或外部命令、可操作程序或批处理文件
名称错误
- 场景 2
@echo off
set name=
set /P TypeName=Name: %=%
if %TypeName% EQA "abcd" goto correctName
if %TypeName% NEQ "abcd" goto wrongName
:correctName
echo Correct Name
:end
:wrongName
echo Wrong Name
:end
当我输入 abcd 作为输入时,我得到EQA is意外此时。
我的脚本中有什么问题吗?我在这里遗漏了什么吗
Here is my batch script file. There are 2 scenarios
- Scenario 1
@echo off
set name=
set /P TypeName=Name: %=%
if %TypeName% == "abcd" goto correctName
else goto wrongName
:correctName
echo Correct Name
:end
:wrongName
echo Wrong Name
:end
When i type abcd as the input, i get 'else' is not recognized as an internal or external command,operable program or batch file
Wrong Name
- Scenario 2
@echo off
set name=
set /P TypeName=Name: %=%
if %TypeName% EQA "abcd" goto correctName
if %TypeName% NEQ "abcd" goto wrongName
:correctName
echo Correct Name
:end
:wrongName
echo Wrong Name
:end
When i type abcd as the input, i get EQA was unexpected at this time.
Is there something wrong in my script?Am I missing something here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ELSE
应与IF
关键字位于同一行,或与属于IF
的右括号位于同一行。像这样:
或者像这样:
Equal 运算符的正确关键字是
EQU
:ELSE
should be on the same line with theIF
keyword or on the same line with the closing bracket that pertains to theIF
.Like this:
Or like this:
The correct keyword for the Equal operator is
EQU
:第一个示例几乎是正确的,只是批处理文件中 IF/ELSE 语句的格式如下:
因此,只要您使用该格式,它就应该可以工作。
The first example is almost right, except that the format of an IF/ELSE statement in a batch file is as follow:
So just you use that format and it should work.
你不一定需要使用 else,就像这样
如果 %TypeName% == "abcd" 它将跳转到 : CorrectName,如果不是,它将简单地落到下一行并跳转到 :wrongName。
You shouldn't necessarily need to use the else, like this
If the %TypeName% == "abcd" it will jump to :correctName, if it doesn't it will simply fall to the next line and jump to :wrongName.
为了结束这篇文章,我以这种方式得到了预期的输出-
To give an end to this post,i got the expected output this way-