Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何对同一IF语句使用多个答案_Batch File_Cmd - Fatal编程技术网

Batch file 如何对同一IF语句使用多个答案

Batch file 如何对同一IF语句使用多个答案,batch-file,cmd,Batch File,Cmd,我使用批处理文件在CMD上创建了一个简单的谜语程序。我希望这样的答案,如一可以回答为1以及。到目前为止,我有: :Riddle_1 cls echo. echo I shake the earth with booming thunder echo fell forests whole and homes complete. echo I influence ships, topple kings echo sweep down swift yet remain unseen. echo. se

我使用批处理文件在CMD上创建了一个简单的谜语程序。我希望这样的答案,如一可以回答为1以及。到目前为止,我有:

:Riddle_1
cls
echo.
echo I shake the earth with booming thunder
echo fell forests whole and homes complete.
echo I influence ships, topple kings
echo sweep down swift yet remain unseen.
echo.
set /p answer=What am I?
if %answer%==wind (goto Riddle_2) else (goto Riddle_1)
当我尝试时:

if %answer%==wind (goto Riddle_2) else (goto Riddle_1)
if %answer%==Wind (goto Riddle_2) else (goto Riddle_1)
它会完全忽略第二个命令,其他变体会这样做,否则它们会忽略else命令,并在答案错误时让它转到下一个问题


有没有办法解决这个问题???

你可以这样做

set res=false
if %answer%==wind set res=true
if %answer%==Wind set res=true
if "%res%"=="true" (
    goto Riddle_2
)
else
(
   goto Riddle_1
)

/i
使比较不区分大小写,双引号使它在各种方面更加健壮

if /i "%answer%"=="wind" (goto Riddle_2) else (goto Riddle_1)

这只需要一个忽略案例的IF,foxidrive演示了如何实现。如果你真的想匹配多个值,比如“风”或“阵风”,那么看看foxidrive的答案更好!