tonelm54
asked on
IF not working
I've got a simple script which is comparing a system variable with a string:-
If I echo out %master_version% I get the correct value:-
So all looks right, but cant get it to fail as wrong version, does anyone know what Im doing wrong?
Thank you
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
If I echo out %master_version% I get the correct value:-
echo %MASTER_VERSION%
W7x64.ent.mui.2014.a.06
So all looks right, but cant get it to fail as wrong version, does anyone know what Im doing wrong?
Thank you
On mobile at the moment but looks like just remove the space before equals you have dot instead of goto
ASKER
Took the space out, but still doesnt work. Got no .
ASKER
So what I have soo far is:-
Which outputs:-
So as you can see both variables are the same, so it should say "Ok", not run wrongVersion
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
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
ASKER
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
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
Steve
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.