Solved

IF not working

Posted on 2014-10-13
6
79 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
How our DevOps Teams Maximize Uptime

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

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …

839 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