Computing.Net > Forums > Disk Operating System > Batch file - using %1

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file - using %1

Reply to Message Icon

Name: michael edwards
Date: January 8, 2003 at 14:03:51 Pacific
OS: windows 98
CPU/Ram: p3 533 - 256
Comment:

I am making batch file and need to know how to do the following

if %1 = "debug" goto debug
if %1 = "normal" goto normal

At the moment I get syntax error

It should be obvious what I am trying to do but if it is not I will explain.

ALSO! if i have a batch file which has been started with batchname parameter then within that batch file, if I type anotherbatchfile %1
will it give the %1 over from the first batch file so it can be used in the second?


Thanks,

Mike



Sponsored Link
Ads by Google

Response Number 1
Name: Wengier
Date: January 8, 2003 at 14:55:36 Pacific
Reply:

First question,you need to use two equal symbols instead of one.

Second question,yes.You can also start the second batchfile by using CALL.


0

Response Number 2
Name: JackG
Date: January 8, 2003 at 15:52:33 Pacific
Reply:

Actually something like:

if %1.==debug. goto debug
if %1.==DEBUG. goto debug

works better. First the "." appended to the %1 parameter and compare solves some strange problems and having a compare for both upper and lower case handles that problem as the compare is case sensitive.



0

Response Number 3
Name: Secret_Doom
Date: January 8, 2003 at 16:08:20 Pacific
Reply:

First thing, use double equal signs. Besides that, you should use a sinbol, like on the example from JackG. That because if you just do:

if %1==DEBUG goto debug

And if %1 is nothing, you'll get a sintax error. That's why you should use the auxiliar character. Which one to use, is up to you. Just keep in mind you must use on both sides:

if %1.==DEBUG. goto debug
if !%1==!DEBUG goto debug
if (%1)==(DEBUG) goto debug
if "%1"=="DEBUG" goto debug

Now, as JackG said, the compare is case sensitive ('debug' different than 'DEBUG' different than 'DeBuG'). JackG's example does NOT make it case insensitive, since the parameter may have both upper and lower case characters (if it's 'DeBuG', it wouldn't goto:debug with his example). I think this one is a better approach for the case insensitive comparison:

set _%1=!!!
if "%_DEBUG%"=="!!!" goto debug

Later one, maybe on the end of the file, unset the variable

set _%1=

Got it all? I hope I were clear.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch file - using %1

Batch file www.computing.net/answers/dos/batch-file/2002.html

Batch files. Using Nul. www.computing.net/answers/dos/batch-files-using-nul/13425.html

Batch file command needed www.computing.net/answers/dos/batch-file-command-needed/2641.html