Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

IF not working

I've got a simple script which is comparing a system variable with a string:-

IF NOT "%MASTER_VERSION%" =="W7x64.ent.mui.2014.a.06" goto wrongVersion
got correctVersion

:wrongVersion
echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
pause

Open in new window


If I echo out %master_version% I get the correct value:-
echo %MASTER_VERSION%
W7x64.ent.mui.2014.a.06

Open in new window


So all looks right, but cant get it to fail as wrong version, does anyone know what Im doing wrong?

Thank you
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

On  mobile at the moment but looks like just remove the space before equals you have dot instead of goto
Avatar of tonelm54
tonelm54

ASKER

Took the space out, but still doesnt work. Got no .
So what I have soo far is:-
echo off
cls

IF NOT "%MASTER_VERSION%"=="W7x64.ent.mui.2014.a.06" goto wrongVersion

:wrongVersion
echo "%MASTER_VERSION%"
echo "W7x64.ent.mui.2014.a.06"

echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
echo Ok

:gotoEnd
pause

Open in new window


Which outputs:-

"W7x64.ent.mui.2014.a.06"
"W7x64.ent.mui.2014.a.06"
---------------------------------------------------------
This is the incorrect script, please run correct.
---------------------------------------------------------
Press any key to continue . . .

So as you can see both variables are the same, so it should say "Ok", not run wrongVersion
Ok, figured it out, it looks like issue was becuase no (), this works:-
echo off
cls

IF NOT "%MASTER_VERSION%"=="W7x64.ent.mui.2014.a.06" (GOTO :wrongVersion) ELSE (GOTO :correctVersion)

:wrongVersion
echo "%MASTER_VERSION%"
echo "W7x64.ent.mui.2014.a.06"

echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
echo Ok

:gotoEnd
pause

Open in new window

Sorry autocorrect 'helping ' on mobile there. Your original had GOT not GOTO so always fell through. Will look at script properly when on PC in bit if wanted.

Steve
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial