2

I can not find solution (or is too complicated for me to understand), I would like to set variable by input

@echo off
set /p var="Choose (AV, RN or I) : " %=%
echo %var%

If value is one of these three then proceed (I will then use that variable to set path, copy,move,start...), else goto exit.

2 Answers 2

4
if /i "%var%"=="AV" goto av
if /i "%var%"=="RN" goto rn
if /i "%var%"=="I" goto i

echo illegal input "%var%"

Quite what you want to do from there, you don't reveal.

The /i after the if means - ignore case. If you insist that the case should match, use if "... - that is, remove the /i

Sign up to request clarification or add additional context in comments.

Comments

2

The simplest way to achieve this is not checking the variable at all, but using its value in a call command with the error messages redirected to nul. This way, if the variable have some of the valid values, the appropriate routine is called; otherwise, nothing happens:

@echo off
set /p var="Choose (AV, RN or I) : " %=%
echo %var%
call :%var% 2> NUL
goto :EOF

:AV
echo Selected: AV
exit /B

:RN
echo Selected: RN
exit /B

:I
echo Selected: I
exit /B

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.