Batch file 带有第二个else的批处理文件if语句
我很难让它工作:Batch file 带有第二个else的批处理文件if语句,batch-file,if-statement,dos,Batch File,If Statement,Dos,我很难让它工作: if /i {%ANSWER%}=={yes} (goto :yes) ELSE (goto :invalid) if /i {%ANSWER%}=={no} (goto :no) ELSE (goto :invalid) if/i{%ANSWER%}={no}(goto:no)ELSE(goto:invalid)不起作用,只有yes的那一个会起作用,还有其他选择吗?我也曾以类似的方式尝试过if-NOT语句,它似乎只是相互抵消(当然)。因为它将直接转到无效的,因为第一个if
if /i {%ANSWER%}=={yes} (goto :yes) ELSE (goto :invalid)
if /i {%ANSWER%}=={no} (goto :no) ELSE (goto :invalid)
if/i{%ANSWER%}={no}(goto:no)ELSE(goto:invalid)
不起作用,只有yes的那一个会起作用,还有其他选择吗?我也曾以类似的方式尝试过if-NOT
语句,它似乎只是相互抵消(当然)。因为它将直接转到无效的,因为第一个if
语句中的else
。只要你的第二个if
将永远不会被评估
我建议只删除第一个或:
if /i {%ANSWER%}=={yes} (goto :yes)
if /i {%ANSWER%}=={no} (goto :no) ELSE (goto :invalid)
请注意,这相当于:
IF /i {%ANSWER%} EQU {yes} GOTO yes
IF /i {%ANSWER%} EQU {no} GOTO no
ECHO Ooops, invalid input.
GOTO :EOF
:yes
ECHO You said YES!
GOTO :EOF
:no
ECHO You said NO!
GOTO :EOF