通过批处理接受基于通配符变量的用户输入

Accepting user input base on wildcard variables via batch

我不知道如何表达这个问题让你们明白,但请耐心等待。下面是我的代码:

set var1=yes no ok get out of here exit quit

echo Do you want to start?

set /p options=Your Input:

if "%Options%" (This is what I need help with)

将用户输入与 var1 进行比较,如果为真,则转到下一个问题 即使用户输入 'Go start',它也会将 Go 或 Start 匹配到 var1。由于 Go 不在列表中,它会尝试将 Start 与 var1 匹配。如果找到,请继续下一个问题。希望有道理

for %%a in (%options%) do for %%b in (%var1%) do if /i "%%a"=="%%b" goto nextq
:not_found
response "%options%" is not implemented
pause

代码证明:

c:6x>q34542866
Do you want to start?
Your Input:go
User input was "go"
response "go" is not implemented

c:6x>q34542866
Do you want to start?
Your Input:no
User input was "no"
response "no" found

c:6x>q34542866
Do you want to start?
Your Input:exit
User input was "exit"
response "exit" found

c:6x>q34542866
Do you want to start?
Your Input:go start
User input was "go start"
response "go start" is not implemented

c:6x>q34542866
Do you want to start?
Your Input:I do want to start, yes please
User input was "I do want to start, yes please"
response "I do want to start, yes please" found

使用代码:

set var1=yes no ok get out of here exit quit
echo Do you want to start?
set /p options=Your Input:

ECHO User input was "%options%"

for %%a in (%options%) do for %%b in (%var1%) do if /i "%%a"=="%%b" goto nextq
:not_found
ECHO response "%options%" is not implemented

GOTO :EOF

:nextq
ECHO response "%options%" found

GOTO :EOF
@echo off
setlocal EnableDelayedExpansion

set "var1= yes no ok get out of here exit quit "
echo Do you want to start?
set /p options=Your Input:

for %%a in (%options%) do if "!var1: %%a =!" neq "%var1%" goto nextquestion
echo Word not found...
goto :EOF

:nextquestion
echo Word found