Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an OR in an IF statement WinXP Batch Script [duplicate]

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.
like image 957
Anthony Miller Avatar asked Sep 01 '11 16:09

Anthony Miller


Video Answer


2 Answers

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
)
like image 172
Joey Avatar answered Oct 05 '22 12:10

Joey


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.

like image 24
myusrn Avatar answered Oct 05 '22 13:10

myusrn