简体   繁体   中英

windows batch command “==” operator weird behavior

I have a windows batch command in jenkins :

set /p Build=<version.txt
IF ("%Build%"=="%VERSION%") (echo version doesn't match)
IF NOT ("%Build%"=="%VERSION%") (echo version match) 

where Build and VERSION are got from the build. The output of the above is

w:\ce-billing-release>set /p Build= 0<version.txt 
w:\ce-billing-release>IF ("1.1.0" == "1.1.0") (echo version match ) 
w:\ce-billing-release>IF NOT ("1.1.0" == "1.1.0") (echo version doesn't match ) 
version doesn't match

Even though it gets the right value of both the variable = 1.1.0 , for some reason it thinks they are not equal. What am I missing ?

Don't use () to delimit the comparison. () aren't meaningful to if , and will become PART of the string being compared:

C:\Users\marc>IF ("1.1.0" equ "1.1.0") (echo version match )

C:\Users\marc>IF "1.1.0" equ "1.1.0" (echo version match )
version match

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM