Solved

IF not working

Posted on 2014-10-13
6
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 54

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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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 video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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