Is there a way to pass an OR through an IF statement?
Such as:
SET var=two
IF "%var%"=="one" OR "two" OR "three" ECHO The number is between zero and four.
No.
if "%var%"=="one" goto foo
if "%var%"=="two" goto foo
if "%var%"=="three" goto foo
goto afterfoo
:foo
echo The number is between one and three (technically incorrect, since it includes the end points and thus is not between).
:afterfoo
If you need a more structured approach:
if "%var%"=="one" set OneToThree=1
if "%var%"=="two" set OneToThree=1
if "%var%"=="three" set OneToThree=1
if defined OneToThree (
echo Foo
) else (
rem something
)
See duplicate question IF... OR IF... in a windows batch file where following solution proposed by @Apostolos
FOR %%a in (item1 item2 ...) DO IF {condition_involving_%%a} {execute_command}
e.g.
FOR %%a in (1 2) DO IF %var%==%%a ECHO TRUE
I found to be the most straight forward and simple to use case in my batch scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With