in DOS batch files, In an IF
statement, is it possible to combine two or more conditions using AND or OR ? I was not able to find any documentation for that
For the AND workaround I agree with Joey, I cannot see another solution.
For the OR workaround I would propose the following 'trick':
Lets say that you want to test if user asked for help on the command line while calling for your batch file, something like: thebatch /?
.
But you don't know if the user will type /?
or rather (being a Unix accustomed user) --help
or -h
or even forget to pass any argument at all.
Your code could be like:
for %%P in ("" "-h" "--help") do if "%1"==%%P (
:help
echo this is my help... >&2
exit /b 9
)
Note however that testing "/?" or "-?" strings won't work with that trick (FOR
loops don't like the ?
meta character).
For that purpose, just add the line: if "%1"=="/?" goto help
on top of the block (see the ':help'
label inside the for
loop ?)
Note too that this syntax won't work (it is just completely ignored and code won't be executed) with batch files under TCC.EXE (the Take Command interpreter, either full or lite edition) but in that case just use their syntax with their .OR.
and .AND.
keywords.
Hope this helps.