Computing.Net > Forums > Disk Operating System > A beginner question

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.

A beginner question

Reply to Message Icon

Name: Hopeless Heng
Date: August 18, 2003 at 03:21:16 Pacific
OS: Win ME
CPU/Ram: P3
Comment:

Ok, this surely is dumb, but what is "%1", "%start%" and "%%f" all these stuffs? I tried to read some tutorials, but they never tell me what are those stuffs and start using it in the tutorial. Thanks for your help.



Sponsored Link
Ads by Google

Response Number 1
Name: JackG
Date: August 18, 2003 at 05:56:28 Pacific
Reply:

When you start a batch file, you can pass it a series of parameters. Each parameter is a text string separated by spaces. How do you access these parameters within the batch file? The "%1" in the batch file gets replace by the string of the first parameter. "%2" gets replaced by the string of the second parameter, and so on through "%9". In addition, the "%0" parameter gets replace by the batch file name.

So if you have MYBATCH.BAT and enter:

MYBATCH IS A good one

%0 = MYBATCH
%1 = IS
%2 = A
%3 = good
%4 = one
%5 through %9 have a null string value.

So if in the batch file you have:

ECHO %3%4

It gets replaced by ECHO goodone and the ECHO command displays "goodone".

So how do you enter more than nine parameters? There is also a SHIFT command, that when executed shifts each of the input parameters left one and discards the first one. So that the values become:

%1 = A
%2 = good
%3 = one
%4 through %9 have a null string value.

And then you could SHIFT it again.

In addition there are a list of Environment variables that have names and a text string associated with it. You can display the current ones with a SET command. In addition you can change or add one to the environment with the SET command:

SET TESTVALUE = TEST

In a batch file, you can access the strings in the environment, in this case the "%TESTVALUE% has the value and gets replaced with the string "TEST". So in this case a batch file line of:

ECHO %3%TESTVALUE%

displays goodTEST

Now %%f and %f are variables you define within the batch file, where the "f: is any alphabetic character(s). You assign a string value to the %%f (or a series of string values) and in the rest of the statement the %f gets replaced by the string.


0

Response Number 2
Name: Nathan
Date: August 19, 2003 at 09:24:18 Pacific
Reply:

also if you are a beginner a good site to visit would be www.computerhope.com and www.robvanderwoude.com (i hope i spelt that right) :)
btw:microsoft gives some surprisingly useful information by typing in command.com "(command) /?" I'm sure you already new this but just in case.


0

Response Number 3
Name: Hopeless Heng
Date: August 19, 2003 at 09:59:53 Pacific
Reply:

Thanks, JackG and Nathan, that' really helpful, especially the reply about the parameters. Btw, maybe I din check clear enough, but http://www.robvanderwoude.com is one of those site who starts using %1 ...etc without explaining it. =)

I have another question, is there any other method to accept user inputs from user except CHOICE? Can a batch prompt and accept strings like "MYBATCH IS A good one"? Thanks again.


0

Response Number 4
Name: Nathan
Date: August 19, 2003 at 19:19:17 Pacific
Reply:

depends if windows ME supports the "set /p" command. goto start>run>cmd
then type "set /?" if there is nothing in there about the "/p" in there then i dont know what to tell you.


0

Response Number 5
Name: Nathan
Date: August 19, 2003 at 19:27:07 Pacific
Reply:

sorry about my previose post i just wanna say i found something at www.batch.hpg.ig.com.br leonardo's web site. SOME GREAT STUFF THERE


0

Related Posts

See More



Response Number 6
Name: Hopeless Heng
Date: August 20, 2003 at 08:14:01 Pacific
Reply:

yeah, no info about set /p there.

Also, I'd already checked Leonardo's website. But the stuffs there's a bit too hard for someone who know lil about batch scripting like me.

I just want to know a simple command that accepts string input, like scanf or gets in C. Help me please. I just need it to write a very simple batch.


0

Response Number 7
Name: Nathan
Date: August 20, 2003 at 14:50:13 Pacific
Reply:

The ONE thing i can think of is finding someone who has win xp and stealing their set.com file. :)

another sulotion would be to get rid of ME. (I NEVER LIKED IT)

if you ask me the emulated dos is better, I know alot of people will go the other way on that.


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: A beginner question

Just a simple questions??? www.computing.net/answers/dos/just-a-simple-questions/10038.html

Before I asked a question? www.computing.net/answers/dos/before-i-asked-a-question/7490.html

A ridiculous question www.computing.net/answers/dos/a-ridiculous-question/10399.html