How to use logical OR in batch script

October 20, 2011 at 23:54:52
Specs: Windows XP, Windows server 2008
Hi,

Please can i know how to make use of logical OR operator in a batch script?

For ex: When i want to check for a particular condition in "IF" statement how should i use it?

if a==1 or b==1

( )

how do i achieve this in batch script?

Thanks in advance


See More: How to use logical OR in batch script

Report •


#1
October 21, 2011 at 02:19:43
@echo off
if %variablename%==1 goto LABEL
if %anothervariable%==1 goto LABEL
goto ELSE

:LABEL
echo DO YOUR THING.
pause
exit

:ELSE
echo ELSE...
pause
exit

Happy is ONE who says I am an OttoMAN.


Report •

#2
October 22, 2011 at 23:27:58
here this should work also the "" 's can be taken out unless you have variables with spaces in them

@echo off

:main
set /p a=a:
set /p b=b:
if "%a%"=="%b%" goto thingboth&if "%a%"=="1" goto thinga&if "%b%"=="1" goto thingb&goto nelse

:thingboth
echo do your thing
echo also both were right
pause>nul
goto main

:thinga
echo do your thing
echo also a was right
pause>nul
goto main

:thingb
echo do your thing
echo also b was right
pause>nul
goto main

:nelse
echo else
pause>nul
goto main


Report •
Related Solutions


Ask Question