What is better: if NOT ...==... or if NOT (... == ...) ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

What is better: if NOT ...==... or if NOT (... == ...) ?

#1 Post by pstein » 25 Nov 2011 03:07

I want to check if both sides of the equl sign are equal.
If not the "If" branch should be executed.

Should I use brackets or not?

if NOT ...==...

or

if NOT (... == ...)

In other words what has a higher priority == or NOT ?

Peter

jeb
Expert
Posts: 1059
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: What is better: if NOT ...==... or if NOT (... == ...)

#2 Post by jeb » 25 Nov 2011 03:18

Hi pstein,

I would recommend the form

Code: Select all

if NOT "%var1%"=="%var2%" ( echo true ) ELSE (echo false)


The "bracket" variant will always result to false :!:
Because batch always make a string compare and the brackets haven't any special meaning there you would compare
(leftside with rightside) also the brackets are compared then.

hope it helps

jeb

Post Reply