Batch File Parameters
Microcomputer/DOS Tutorial


Computer Studying

Navigation
{NavForms}

Virus Tutorial Map
Tutorial Map

Parameters are extra pieces of information that you type after many of the DOS commands. For example, "DIR B: /W" contains the parameters B: and /W. These modify the basic operation of the command, but are not required by the command.

You pass parameters to a batch file in the same manner; by typing the information after the batch command, but before tapping the Enter key.

The parameters may be used in any place in the batch file where a parameter would normally be used as part of the DOS command being run.

Markers are used within the batch file to signify which parameter goes where. Markers are comprised of a percent sign (%) and a single digit between 0 and 9 (that's ten markers in use at any one time; remember, zero is a number).

As an example:

Assume that a batch file named REPEAT.BAT is on the current drive. This file contains two commands: "ECHO OFF" which stops DOS from showing commands and "ECHO %1 %3" where the ECHO command can show messages on the screen. If, at the DOS prompt you typed "REPEAT Red Blue Green" your screen would show "Red Green" as shown in the screen capture:

Batch File Parameter Example

In this simple example, three parameters were passed to the batch file and were placed into the ECHO command in the order received. Only the first and third are shown as only those were referenced in the batch file.

The parameters and markers were related as follows...

  • %1 is marker 1 and, in this example, represents "Red", the first parameter;
  • %3 is marker 3 and, in this example, represents "Green", the third parameter;
  • %2 would be marker 2 but, in this example, is not present so "Blue", the second parameter, is ignored.

Note: Marker zero is assigned the name of the batch file in the form you typed it in (i.e., all caps, all lower case, or a mixture).

Keep Reading Subcommands


{NavBar}
Home | Products | Definitions | Newsletter | Virus Tutorial | Contact


FILExt is proudly hosted by DewaHost.com - a fast and reliable host for everyone!
DewaHost offers premium Web hosting starting from $8.95/month and a high speed file hosting service FileBurst!

Please use the contact form for questions or comments about this web site.
Copyright © 2001 Computer Knowledge, All Rights Reserved
Pray the Rosary for peace.