Batch Files

Batch Files

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >

Replaceable Parameters

Learning objective: (2) Explain the use of replaceable parameters in batch files


Click on image to enlarge.

Replaceable parameters allow you to pass data from the command line into the batch file when it is executed. There is a corresponding 1:1 relationship between what is entered on the command line and the replaceable parameter referenced in the batch file. These make batch files significantly more versatile. In the batch file, the replaceable parameter is referenced by a percent sign followed by a number between 1 and 9. Percent zero references the command entered on the command line.

%0 batch file

%0 is the reference to the command being processed. When used with a batch file, it is the name of the batch file.

%1 - %9 replaceable parameters

%1 - %9 represents data being passed from the command line to the batch file. Each parameter is separated by one or more spaces that act as a delimiter. For example, in "DEMO.BAT one two three" %0 is "DEMO.BAT", %1 passes a value of "one", %2 passes a value of "two", and %3 passes a value of "three" to the batch file. These values can be tested by the IF command for further action.

Thinking: Why allow content to be changed at runtime within a batch file?

Key terms: %n, argument, replaceable parameters

Resources:
To maximize your learning, please visit these Web sites and review their content to help reinforce the concepts presented in this section.

Quick links:
Replaceable Parameters @ bristolcc.edu
DOS Batch File Replaceable Parameters @ algonquincollege.com

Embedded Resources

Notes on navigation: Click inside the frame to navigate the embedded Web page. - Click outside the frame to navigate this page to scroll up/down between the embedded Web pages. - Click on the frame title to open that page in a new tab in most browsers. - Click on the the "Reload page" link to reload the original page for that frame.

Replaceable Parameters @ bristolcc.edu | Reload page | If frame is empty, click on the link to view the page in a new tab or window

DOS Batch File Replaceable Parameters @ algonquincollege.com | Reload page | If frame is empty, click on the link to view the page in a new tab or window

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >