Page 1 of 1

BATCH: IF ELSE STATEMENT

Posted: Thu Feb 23, 2006 11:18 pm
by vietboy505
IF ELSE STATEMENT

Since there is no else statement in Batch script. How do I by pass that?

I want this script will ask for a name if the name doesn't match the input.
The name will be hardcode, so the person who run it doesn't enter his/her name everything. It just goes directly to check status right away and print out the message.

Why this not working the way I want it?
This will goes through all command even though I try to put in JOHN or DAVE.

How can I covert the user input to all CAPS or the variable %NAME% to all CAPS?
---------

Code: Select all

@ECHO OFF
SET NAME="ENTER_NAME_HERE"
GOTO :START_MENU

:START_MENU
IF %NAME% == "ENTER_NAME_HERE" GOTO :ASK_MENU
:END


:ASK_MENU
SET /P NAME="ENTER NAME: " GOTO :CHECK_MENU
:END

:CHECK_MENU
IF %NAME% == "JOHN" GOTO :JOHN_MENU
IF %NAME% == "DAVE" GOTO :DAVE_MENU
:END

:JOHN_MENU
ECHO YOUR NAME IS: %NAME% HAVE A NICE DAY!
:END

:DAVE_MENU
ECHO YOUR NAME IS: %NAME% PEACE OUT!
:END

PAUSE

---------------

thanks for the help..

Posted: Fri Feb 24, 2006 12:27 am
by anjanesh
Batch script supports IF NOT - you can use this instead of an ELSE.

Posted: Fri Feb 24, 2006 8:52 am
by vietboy505
how IF NOT can work?

Right now, it just go through all the command regardless of what my input is.

Posted: Sat Feb 25, 2006 8:17 pm
by Ambush Commander
You duplicate the condition.

Needless to say, personally, I tried using batch scripts and they're just really... stupid. I didn't feel like learning Perl so I use PHP for all my administrative scripting. It's great. I have all the bat files that are like...

Code: Select all

@echo off
php C:\php\switch.php %*