user3358206
user3358206

Reputation: 11

Using & in if batch file commands

I have a problem. Lets say that I want to link two IF commands to have an answer.

For example a batch file:

@echo off

IF %a%== 123 AND IF %b%== 456 then COMMAND.

How can I link the two if's

Upvotes: 1

Views: 96

Answers (3)

Andriy M
Andriy M

Reputation: 77737

Another method, somewhat specific to your particular pair of conditions:

IF "%a%.%b%" == "123.456" command

Upvotes: 0

foxidrive
foxidrive

Reputation: 41297

This is all you need, but it can be enhanced to protect against spaces and & characters etc.

@echo off
IF %a%==123 IF %b%==456 COMMAND

Upvotes: 2

morepaolo
morepaolo

Reputation: 631

In batch there's no AND operator, you can emulate it by a series of if-clauses in cascade

http://www.robvanderwoude.com/battech_booleanlogic.php

IF %a% EQ 123 (
        IF %b% EQ 456 (
            ' do your fancy stuff...
        )
)

Upvotes: 2

Related Questions