an IBM machine you can get this
character if you hold the ALT key and
press 2-5-5 on the numeric keypad.
On other machines, or with certain
editors, the procedure may be diffe-
rent.

	You may want to shut up the dis-
play at some stage. To do this you
set ECh10 OFF so that you won't see
the batch procedure running, but cer-
tain commands still natter at you.
The bit bucket 'file' NUL may be
used for this. If your file contains the
statement

	DEL *.BAK>NUL
then it will attempt to delete all back-
up files. If there are none, the error
message will be redirected into the
97th dimension and will not be seen.
You couid also get the effect with the
statement

	IF EXIST *.SAK DEL *.BAK
but this wouid require a bit of extra
time for the existence test. IF EXIST
only works for files in the corrent
drive and directory, which is some-
times a bother.

Variables

There are-four kinds of variabies in
batch processing. %O returns the
name of the batch file itself while
%1, %2, %3 represent tolcens passod
in on the command line after the
name of the batch file. %%A' where
'A' may be any character, is the form
of a variable that takes successive
values of the 'IN' portion of a FOR
statement.

	The usual literature does not make
it obvious that a variabie in the form
%WORD% will return the value of a
variable called 'WORD' that has been
set into the 'environment'. To install
such a variable, you execute a com-
mand, in or out of a batch file, of the
form

	SET VAR=SOME STRING
where VAR is the variable namer and
the value is any string.

	To see how SET works, try the fol-
lowing batch program.

ECHO OFF

SET X=NOT

ECHO THIS DOES %X% FAIL.

SET X=

ECtlO THIS DOES %X% FAIL.

These variables set into the environ-
ment are made available to ali ex-
ecutable programs, and this is how
they are accessed by .BAT programs.

	Often you may need to control
batch file behaviour according to
whether a variable exists or not (re-
gardless of its value). The IF state-
ment does not directly test for this;
you must supply some minimal
string on both sides of the '=='
operator. I'll use a minimal string of
'@' to show the two basic kinds of
existence tests.

Executes if the variable %1 exists.
IF NOT %1@==~? . ..

Executes if the variable %1 does not
exist:

IF %1@==@...

	Later we'll see sorne other uses for
these techniques but'as an example,
suppose you have a program that
becomes memory-resident when cal-
led, and if called again will install
another copy of itself' gradually eat-
ing up your available memory (some
otherwise excellent commercial pro-
ducts have been known to behave
like this). The program is not used
every day, and is too large to install
no matter what with AUTOEX-
EC.BAT. What you need is a batch
program tbat calls this maverick
program if it is needed, but only
once per session. Let's suppose our
resident-type program is called
DBSORT. A batch file fragment that
wouid do the trick might be:

IF NOT %SORT%~==

INS@ DBSORT

IF NOT %SORT%@==

INSQ? SET SORT=INS

	After DBSORT is installed once'the
variable SORT is set to INS ~n the
environment and, therefore, DESORT
will not again be called until the
machine is rebooted.

Creating a file with a
batch file

The command 'ECHO This is a test
message >TEST.TXT' will create a
one-line file~ named TEST.TXT wh ich
contains the words 'This is a test
message'. One reason to do this
wouid be to set a flag that will last
between sessions. Things set in the
environment go away with the pow-
er' but a temporarily-created file will
not, and its existence may be tested
by the IF EXIST statement of betch
processing. Your AUTOEXEC.SAT
might want to set up a large print
spooler if you have a dot-matrix prin-
ter installed, and omit the spooler if
a daisywheel unit is attached. The
following statement in AUTOEX-
EC.BAT wouid do it, based on the
existence or not of a fite called
DAISY.

IF NOT EXIST DAISY BIGSP00L1128

	At some point in your configura-
tion procedure you could create the
flag file if required with the state-
ment:

ECHO Daisywheel printer
installed~DAISY

	You can create a temporary file
and then use the temporary file to
answer a question. Two commands
that a re hard to automate are DE L
and PRINT, because under certain
conditions they ask questions of the
user. The following batch sequences
will proceed without pause;

ECHO Y >YES
DEL *.* cYES
ECHO LPT1 ~PSPEC
PRINT %1 <PSPEC

DEL PSPEC

	In each case, if the procedure asks
a question, it finds a file waiting with
the answer, and it takes the answer
from the file.

	A multiple line file may be written
a line at a time, by using the '>~'
operator, which adds a line to a file.
'>>' creates the file if it deesn't yet
exist. The following sequence writes
a three-line file (try it).

DEL TEMP
ECHO This is the first line

	>>TEMP
ECHO This i5 the second line

	>>TEM P
ECHO This is yet another line

	>>TEMP
TYPE TEMP

	You couid even write another
betch file this way and then execute
it! Here is how to create a program
that keeps an activity log. First create
a file that contains only a carriage
return and a tine feed by the follow-
ing procedure:

COP~f CON CRLF.BAT creturn~
creturn>

cCTRL-Z> creturn>

	We've named this weird little file
CRLF.BAT because there is another
,mportant use for it that we'll discov-
er below. One use for this will come
ciear if you try

DATE c CR LF. BAT
and then

DATE ~CRLF.BAT >LOG
TYPE LOG

This, then, wouid be your activity log
program fragment. It records a date
and time in file LOG whenever it
runs:

DATE cCRLF.BAT >>LOG
TIME cCRLF.BAT >>LOG
For maximum speed we compress
this to:

FOR %%~? IN (DATE TIME} DO
%%@

~CRLF.BAT >>LOG

	You couid also use th~s technique
to put data in a file. Below we will
see how a batch file couid read such
data.

Chaining

As is well-known, if you name
another batch file in a batch file, the
next batch file begins executing. In
this way batch files may be chained.
This chaining can be used to cause
an abrupt exit from a long batch file
that runs slowly. Suppose the batch
file has the following structure:

: LABEL1

cFIRST PROCEDURE>
GOTO EXIT

:LABEL2

cSECOND PROCEDURE
GOTO EXIT

: LAST LABE L
<LAST PROCEDURE>
: EX IT

	This is likely to execute slowly be-
cause after any given procedure is
executed, EXIT is called and the
batch processor must read the whole
file from the beginning to find the

~,~

