Solved

IF not working

Posted on 2014-10-13
6
78 Views
Last Modified: 2014-10-17
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
0
Comment
Question by:tonelm54
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40376808
On  mobile at the moment but looks like just remove the space before equals you have dot instead of goto
0
 

Author Comment

by:tonelm54
ID: 40376842
Took the space out, but still doesnt work. Got no .
0
 

Author Comment

by:tonelm54
ID: 40376853
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
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:tonelm54
ID: 40376858
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

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40376974
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
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40379594
You had a couple of typos in your first post, I think this would correct those:
IF NOT "%MASTER_VERSION%" == "W7x64.ent.mui.2014.a.06" goto wrongVersion
goto correctVersion

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

:correctVersion
pause

Open in new window

However, I would suggest a slight rewrite to look like this.  It avoids the goto's which is typically a little easier to follow and maintain.
IF "%MASTER_VERSION%" == "W7x64.ent.mui.2014.a.06" (
  echo ---------------------------------------------------------
  echo This is the incorrect script, please run correct.
  echo ---------------------------------------------------------
  pause
  goto :EOF
)

pause

Open in new window

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question