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
Edit - help if
and the MS docs say nothing about using more than one condition in an if.
I guess a workaround for AND would be to do
if COND1 (
if COND2 (
cmd
)
)
but this is exactly what I'm trying to avoid.
[ == ] (Double Equals) The "IF" command uses this to test if two strings are equal: IF "%1" == "" GOTO HELP. means that if the first parameter on the command line after the batch file name is equal to nothing, that is, if a first parameter is not given, the batch file is to go to the HELP label.
The command processor component in the Windows operating system that accepts and executes instructions on a command line. While providing more flexibility, CMD. EXE supports most of the operations that were previously handled with the COMMAND.COM processor in DOS.
If it's an internal cmd command or a batch file, then the command processor is run with the /K switch to cmd.exe. The /K switch keeps the window open after the command is run.
Windows Command Prompt (also known as the command line, cmd.exe or simply cmd) is a command shell based on the MS-DOS operating system from the 1980s that enables a user to interact directly with the operating system.
No, there is no easier way.
For and
you can also just chain them without introducing blocks:
if COND1 if COND2 ...
which frankly isn't any worse than
if COND1 and COND2 ...
However, for or
it gets uglier, indeed:
set COND=
if COND1 set COND=1
if COND2 set COND=1
if defined COND ...
or:
if COND1 goto :meh
if COND2 goto :meh
goto :meh2
:meh
...
:meh2
I once saw a batch preprocessor which used C-like syntax for control flow and batch stuff in between and then converted such conditionals into multiple jumps and checks. However, that thing was for DOS batch files and was of little to no use in a Windows environment.
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