If statement problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Cander
Posts: 7
Joined: 01 Jan 2009 15:35

If statement problem

#1 Post by Cander » 13 Jan 2009 01:34

I just figured out that it's some strange with this...

This works as long you don't use spaces or like semicolon etc in the variable. Then the batch crash and I don't know why...

Code: Select all

@echo off
Set /p connect=Users IP Address/computername:
IF /i %connect%==end (
GOTO END
) ELSE (
echo %connect%
pause
GOTO VERYEND
)

:END
pause

:VERYEND


What I'm doing wrong? It feel like I have done this before and got it working...

EDIT: Oh, is screws up when it trying to compare if the variable contains multiple words. Puting " " around the %connect% simply solved the problem, because the connect variable may sometimes contain multiple words depending on what the user put into it. Got to always keep that then... Nervermind.

Code: Select all

@echo off
Set /p connect=Type anything:
IF /i "%connect%"==end (
GOTO END
) ELSE (
echo %connect%
pause
GOTO VERYEND
)

:END
pause

:VERYEND

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2009 01:37

Cander,

I think you also need quotes around the "end".
Short:

Code: Select all

@echo off
Set /p connect=Type anything:
IF /i "%connect%"=="end" pause&goto:eof
echo %connect%
pause

right?

Post Reply