Introduction to Batch Files, Part II

by Evelyn Brown

The Echo and Pause Commands

In last month’s article I listed nine special DOS commands that are called the Batch file commands: Call, Choice, Echo, For, Goto, If, Pause, Rem and Shift.

This time, we will take a look at how the Echo and Pause commands work, and how they may be used in batch files.

The Echo command instructs the computer to display a message. By default, the display is directed to the monitor. Echo can be written in such a way as to override the default option and send the message to the printer, or to a file on a hard or floppy disk inste ad of to the monitor. This is called Redirection, and is accomplished by using what is called a redirection character - the greater than sign, ( >) which looks like a right pointing arrow.

Echo without parameters asks DOS the question “Is echo on or off”. The computer responds with the message “Echo is on” or “Echo is off”.

The command “Echo on” will turn echo on, and “Echo off?” will turn echo off. In a batch file, echo off keeps the interpreter from displaying each command it encounters during execution. This prevents screen clutter, and allows the users to see only the c omments and instructions intended for them. Echo off at the command line turns off the prompt display, and is of limited usefulness.

Echo followed by the Pause command is used in batch files to instruct the operator to do something, such as insert a disk, that has to be accomplished before processing can resume. After the instruction is displayed, the pause command displays the message “press any key to continu e”, and waits until a key is pressed before continuing. Note: The space bar makes a good “any” key, since it’s the largest key on the keyboard, and is easily reached by either thumb.

Redirecting to a file:

Echo with redirection to a filename can be used to create a file (>) or add to an existing file (>>).

Creating a new file:

Savepath.bat is batch file that uses echo to create another batch file called Setpath.bat. Savepath stores the new batch file in the root directory of the default drive - not in the BAT directory, so it can be found and executed even when no path exists.

@echo off

cls

rem SAVEPATH.BAT

echo @echo off > \SETPATH.BAT

echo cls >> \SETPATH.BAT

echo rem SETPATH.BAT >> \SETPATH.BAT

echo path=%path% >> \SETPATH.BAT

Adding to a file:

The following command in a batch file (or typed at the command line prompt) can be used to add a statement to the config.sys file:

Echo device=C:\dos\ansi.sys >> C:\Config.sys <enter>

Warning: If you try this, be very careful to include two redirection characters, or you will wipe out your Config.sys file and have only a new one consisting of the single line you meant to add.

Note: It is a good habit to ALWAYS save a copy of your Config.sys and Autoexec.bat files before you make any changes to them.

Next time - Combining Echo with Shift and using Replaceable parameters.

Evelyn Brown, a HAL-PC member, is the Saturday DOS Instructor/coordinator.


E-mail me at webmaster@hal-pc.org with any comments you have and tell me what you want to see here.

Back to the Magazine Home Page