BATCH: IF ELSE STATEMENT

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

BATCH: IF ELSE STATEMENT

Post 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..
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Batch script supports IF NOT - you can use this instead of an ELSE.
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

Post by vietboy505 »

how IF NOT can work?

Right now, it just go through all the command regardless of what my input is.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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 %*
Post Reply