30 The following notation is used below:
32 [item] item is optional.
33 item* item is repeated 0 or more times.
34 item+ item is repeated 1 or more times.
36 item1 is present or item 2 is present but
38 <object> indicates a syntactic variable.
43 COMMAND [[<drive>:]<path>] [<cttydev>] [-D] [-P] [-C <string>]
45 -P If present COMMAND will be permanent, otherwise
46 this is a transient command.
48 -D If present COMMAND will not prompt for DATE and
49 TIME when it comes up.
51 d: Specifies device where command will look for
52 COMMAND.COM current default drive if absent.
54 <Path> Specifies a directory on device d: root
57 <cttydev> Name of the CTTY device. /DEV/CON if absent
58 and command is permanent. The /DEV/ may be left
59 off if AVAILDEV is TRUE (see sysinit doc).
61 -C <string> If present -C must be the last switch.
62 This causes COMMAND to try to execute the string
63 as if the user had typed it at the standard input.
64 COMMAND executes this single command string and
65 then exits. If the -P switch is present it is
66 ignored (can't have a single command, permanent
67 COMMAND). NOTE: ALL of the text on the command
68 line after the -C is just passed on. It is not
69 processed for more arguments, this is why -C must
74 IF <condition> <command>
76 where <condition> is one of the following:
79 true if and only if the previous program EXECed by
80 COMMAND had an exit code of <number> or higher.
82 <string1> == <string2>
83 true if and only if <string1> and <string2> are
84 identical after parameter substitution. Strings
85 may not have embedded delimiters.
88 true if and only if <filename> exists.
91 true if and only if <condition> is false.
93 The IF statement allows conditional execution of commands.
94 When the <condition> is true, then the <command> is
95 executed otherwise, the <command> is skipped.
99 IF not exist /tmp/foo ECHO Can't find file /tmp/foo
101 IF $1x == x ECHO Need at least one parameter
103 IF NOT ERRORLEVEL 3 LINK $1,,;
106 FOR %%<c> IN <set> DO <command>
108 <c> can be any character but 0,1,2,3,..,9 (so there is no
109 confusion with the %0 - %9 batch parameters).
113 The %%<c> variable is sequentially set to each member of
114 <set> and then <command> is evaluated. If a member of
115 <set> is an expression involving * and/or ?, then the
116 variable is set to each matching pattern from disk. In
117 this case only one such <item> may be in the set, any
118 <item>s after the first are ignored.
122 FOR %%f IN ( *.ASM ) DO MASM %%f;
124 for %%f in (FOO BAR BLECH) do REM %%f to you
126 NOTE: The '%%' is needed so that after Batch parameter
127 (%0 - %9) processing is done, there is one '%' left.
128 If only '%f' were there, the batch parameter processor
129 would see the '%' then look at 'f', decide that '%f'
130 was an error (bad parameter reference) and throw out
131 the '%f' so that FOR would never see it. If the FOR
132 is NOT in a batch file, then only ONE '%' should be
138 Currently, command files are limited to handling 10
139 parameters: %0 through %9. To allow access to more than
140 these, the command SHIFT will perform a 'pop' of the
141 command line parameters:
148 then a SHIFT will result in the following:
154 If there are more than 10 parameters given on a command
155 line, then the those that appear after the 10th (%9) will
156 be shifted one at a time into %9 by successive shifts.
160 This is essentially a no-op. It defines a label in the
161 batch file for a subsequent GOTO. It may also be used to
162 put comment lines in batch files since all lines that
163 start with ':' are ignored.
167 Causes commands to be taken from the batch file beginning
168 with the line after the <label> definition. If no label
169 has been defined, the current batch file will terminate.
177 will produce a infinite sequence of messages:
180 NOTE: Labels are case insensitive, :FOO == :foo == :Foo
183 ECHO [{ON | OFF | <message>}]
185 Normally, commands in a BATCH file are echoed onto the
186 standard output as they are seen by COMMAND. ECHO OFF
187 turns off this feature. ECHO ON turns echoing back on.
188 If ON or OFF is not specified and there is text following
189 the command, that text (a message) is echoed to standard
190 output. If there are no arguments at all, the current
191 setting of echo (on or off) is echoed to the standard
196 Where xxx is "on" or "off".
198 Redirection of standard input/standard output.
200 Programs that read from the keyboard and write to the
201 screen are said to be doing I/O to the standard input and
202 standard output. Using any of the following will result
203 in I/O to these standard devices:
205 Writing to default handles 1 / read from default
208 Doing byte I/O using system calls 1, 2, 6-12.
210 These standard devices may be redirected to/from files by
211 the following in command line arguments:
214 causes <filename> to be created (or truncated to
215 zero length) and then assigns standard output to
216 that file. All output from the command will be
220 causes standard input to be assigned to
221 <filename>. All input to the command will come
222 from this file. If end-of-file is reached, then
223 system calls 1, 2, 6-12 will return ^Z , while
224 reading from handle 0 will return zero characters.
227 causes <filename> to be opened (created if
228 necessary) and positions the write pointer at the
229 end of the file so that all output will be
230 appended to the file.
232 Note that the above will not appear in the command line
233 that the program being invoked sees.
238 Sends the output of the dir command to the file
242 FOR %0 IN (*.ASM) DO MASM %0; >>ERRS.LST
243 Sends all error output from assembling every .ASM file
244 into the file ERRS.LST.
246 Piping of standard I/O
248 It is often useful for the output of one program to be
249 sent as input to another program. A typical case is a
250 program that produces columnar output that must later be
253 The pipe feature allows this to occur naturally is the
254 programs do all of their I/O to the standard devices.
256 For example, if we had a program SORT that read all of
257 it's standard input, sorted it and then wrote it to the
258 standard output, then we could get a sorted directory
263 The | would cause all standard output generated by the
264 left-hand command to be sent to the standard input of the
267 If we wanted the sorted directory to be sent to a file, we
274 The piping feature is implemented as sequential execution
275 of the procedures with redirection to and from temporary
276 files. In the example above, the following would be an
280 SORT </tmp/std1 >FILE
284 The pipe is not a real pipe but rather a quasi-pipe
285 that uses temporary files to hold the input and output as
286 it sequentially executes the elements of the pipe. These
287 files are created in the current directory, of the current
288 drive and have the form %PIPEx%.$$$, where x will be 1 or
289 2. This means that any program that runs in the pipe must
290 be sure to restore the current directory and drive if it
291 has changed them, otherwise the pipe files will be lost.
295 Prints DOS version number.
298 Prints the volume ID of the disk in drive d:. No d: does
301 CHDIR [{<drive>: | <path>}]
302 Change directory, or print current. directory.If no
303 argument is given, the current directory on the default
304 drive is printed. If d: alone is given, the durrent
305 directory of drive d is printed. Otherwise the current
306 directory is set to path.
308 NOTE:"CD" is accepted as an abbreviation.
310 MKDIR <path> - Make a directory.
311 "MD" is accepted as an abbreviation.
313 RMDIR <path> - Remove a directory.
314 "RD" is accepted as an abbreviation.
315 The directory must be empty except for
318 <path> - A standard XENIX style path with the optional
319 addition of a drive spec:
322 /FOO/BAR Full path, current drive
323 FOO/BAR Current dir relative
327 Select/deselect verify after write mode. This supliments
328 the V switch to the COPY command. Once turned ON, it
329 stays on until some program changes it (via the set verify
330 system call) or the VERIFY OFF command is given. If no
331 argument is given, the current setting of VERIFY is
332 printed to the standard output in the form:
336 Where xxx is "on" or "off".
338 PATH [<path>{;<path>}*]
339 Set command search paths. This allows users to set
340 directories that should be searched for external commands
341 after a search of the current directory is made. The
342 default value is /bin. In addition there are two special
343 cases: PATH all by itself with no arguments will print
344 the current path. Path with the single argument ';' (ie.
345 "PATH ;") will set the NUL path (no directories other than
346 the current one searched). If no argument is given, the
347 current value of PATH is printed to the standard output in
354 NOTE: On IBM systems, the default value of path is No
358 For COMMANDs run without the P switch, this causes COMMAND
359 to return. For a normal COMMAND it causes a return to
363 Like in CONFIG.SYS, "BREAK ON" turns on the Control C
364 check in the DOS function dispatcher. "BREAK OFF" turns
365 it off. If no argument is given the setting of BREAK is
366 printed to the standard output in the form:
370 Where xxx is "on" or "off".
372 PROMPT [<prompt-text>]
373 Set the system prompt. MS-DOS prompts are now user
374 settable, all of the text on the command line is taken to
375 be the new prompt. If no text is present the prompt is
376 set to the default prompt. There are meta strings for
377 various special prompts. These are of the form '$c' where
378 c is one of the following:
380 $ - The '$' character.
383 p - The current directory of the default drive.
384 v - The version number.
385 n - The default drive.
386 g - The '>' character.
387 l - The '<' character.
388 b - The '|' character.
389 s - The ' ' character.
390 e - The ESC character.
391 _ - A CR LF sequence.
395 Would set the normal MS-DOS prompt.
397 Would det the normal PC-DOS prompt.
398 PROMPT Time = $t$_Date = $d
399 Would set a two line prompt which printed
400 Time = (current time)
401 Date = (current date)
403 NOTE: For '$c' sequences, lower case = upper case, and
404 any character not on the above list is mapped to
407 SET (ENVNAME)=(ENVTEXT)
408 Set environment strings. This command inserts strings in
409 COMMAND's environment. For instance:
412 Duplicates the function of the PROMPT command.
414 Duplicates the function of the PATH command.
416 Puts the string FOO=bar into the environment (note the
417 case mapping of (ENVNAME)).
419 NOTE: Environments are very flexible, almost anything can
420 be put into the environment with the SET command; the
421 only requirement is that a single '=' be present in
425 Clear screen, causes the ANSI escape sequence ESC[2J to be
426 sent to standard output.
428 CTTY /DEV/dev - Change console TTY. For instance:
432 Would move all command I/O to the AUX port.
436 Would move it back to the normal device. The
437 /dev/ prefix may be left off if AVAILDEV is
438 TRUE (see configuration-file doc).
440 COMMAND internal commands take path arguments.
447 If the path is a dir, all files in that dir
449 NOTE: The "Are you sure (Y/N)" prompt for DEL and
450 ERASE now uses buffered standard input, so
451 users must type a return after their answer.
452 This gives them the chance to correct if they
455 TYPE <path> (must specify a file)
460 FILCOM - compare two files
462 The FILCOM program compares two files and produces a log
463 of differences between them. The comparison may be made
464 in two fashions; either on a line-by-line basis, or on a
467 The line-by-line compare will isolate blocks of lines that
468 are different between the two files and will print the
469 blocks from each file. The line-by-line compare is the
470 default when neither of the two files being compared has
471 the extension .EXE, .COM, or .OBJ.
473 The byte-by-byte compare will display exactly which bytes
474 are different between the two files. If either file being
475 compared has extension .EXE, .COM, or .OBJ then the files
476 will be compared in byte-by-byte mode.
480 RECOVER - recover files from a trashed disk.
482 If a sector on a disk goes bad, you can recover either the
483 file that contained that sector (without the sector) or
484 the entire disk (if the bad sector was in the directory).
486 To recover a particular file:
488 RECOVER <file-to-recover>
490 This will cause the file to be read sector by sector and
491 to be have the bad sector skipped. Note that this implies
492 that the allocation unit containing the bad sector will be
493 read as much as possible. When such a bad sector is
494 found, its containing allocation unit is marked as bad,
495 thus preventing future allocations of that bad sector.
497 To recover a particular disk:
499 RECOVER <drive-letter>:
501 This will cause a scan to be made of the drive's FAT for
502 chains of allocation units (files). A new root directory
503 is then written that has entries of the form FILEnnnn.
504 Each FILEnnnn will point to the head of one of the
505 allocation unit chains.
507 If there are more chains than directory entries in the
508 root, RECOVER prints a message and leaves the un-RECOVERED
509 chains in the FAT so that RECOVER can be run again once
510 some room has been made in the ROOT.
517 When 2.0 DEBUG is invoked it sets up a program header
518 atoffset 0 in its program work area. On previous versions it
519 was OK to overwrite this header with impunity: this is true
520 of the default header set up if no <filespec> is given to
521 DEBUG. If DEBUGging a .COM or .EXE file, however, you must be
522 careful not to tamper with the header of the program below
523 address 5CH, to do this will probably result in a crash. It
524 is also important that an attempt is not made to "restart" a
525 program once the "program terminated normally" message is
526 given. The program must be reloaded with the N and L commands
527 in order for it to run properly.
531 The A (Assemble) Command
533 FORMAT: A [<address>]
535 PURPOSE: To assemble 8086/8087/8088 mnemonics directly into
538 o If a syntax error is encountered, DEBUG responds with
542 and redisplays the current assembly address.
544 o All numeric values are hexadecimal and may be entered
547 o Prefix mnemonics must be entered in front of the opcode
548 to which they refer. They may also be entered on a
551 o The segment override mnemonics are CS:, DS:, ES:, and
554 o String manipulation mnemonics must explictly state the
555 string size. For example, the MOVSW must be used to
556 move word strings and MOVSB must be used to move byte
560 o The mnemonic for the far return is RETF.
562 o The assembler will automatically assemble short, near
563 or far jumps and calls depending on byte displacement
564 to the destination address. These may be overridden
565 with the NEAR or FAR prefix. For example:
567 0100:0500 JMP 502 ; a 2 byte short jump
568 0100:0502 JMP NEAR 505 ; a 3 byte near jump
569 0100:0505 JMP FAR 50A ; a 5 byte far jump
571 The NEAR prefix may be abbreviated to NE but the FAR
572 prefix cannot be abbreviated.
574 o DEBUG cannot tell whether some operands refer to a word
575 memory location or a byte memroy location. In this case
576 the data type must be explicity stated with the prefix
577 "WORD PTR" or "BYTE PTR". DEBUG will also except the
578 abbreviations "WO" and "BY". For example:
583 o DEBUG also cannot tell whether an operand refers to a
584 memory location or to an immediate operand. DEBUG uses
585 the common convention that operands enclosed in square
586 brackets refer to memory. For example:
588 MOV AX,21 ;Load AX with 21H
589 MOV AX,[21] ;Load AX with the contents
590 ;of memory location 21H
592 o Two popular pseudo-instructions have also been included.
593 The DB opcode will assemble byte values directly into
594 memory. The DW opcode will assemble word values directly
595 into memory. For example:
597 DB 1,2,3,4,"THIS IS AN EXAMPLE"
598 DB 'THIS IS A QUOTE: "'
599 DB "THIS IS A QUOTE: '"
601 DW 1000,2000,3000,"BACH"
604 o All forms of the register indirect commands are supported.
607 ADD BX,34[BP+2].[SI-1]
611 o All opcode synonyms are supported, For example:
619 o For 8087 opcodes the WAIT or FWAIT prefix must be
620 explictly specified. For example:
622 FWAIT FADD ST,ST(3) ; This lines will assemble
625 FLD TBYTE PTR [BX] ; This line will not
631 FORMAT will now install volume id's during the format
632 process. DIR and CHKDSK will display these volume id's.
634 User programs can read the volume id on a particular drive
635 by doing a 'search next' with the volume id attribute. It
636 is impossible, using normal DOS calls, to delete a volume
637 id or to create another one. The only way to create a
638 volume id is to reformat the disk.
640 NOTE: On IBM systems the V switch must be given to FORMAT
641 to have it do Volume IDs.
646 CHKDSK FOR MS-DOS 2.0
649 MS-DOS 2.0 has a tree structured directory scheme which
650 did not exist on previous versions of MS-DOS. As a result
651 CHKDSK is a much more complex program than in previous
652 versions since it must perform a tree traversal to find all of
653 the files on a given disk. It employes a depth first
654 traversal in order to accomplish this.
656 Previous versions of CHKDSK automatically "fixed"
657 disks (regardless of whether it was appropriate). CHKDSK 2.00
658 run normally will not alter the disk in any way, it simply
659 reports on any inconsistencies found. To actually "fix" a
660 disk CHKDSK must be run with the F switch (Fix). This allows
661 you to perhaps take some alternate (to CHKDSK repairs) action
662 before letting CHKDSK loose on your disk.
664 CHKDSK 2.00 will report on non-contiguous allocation units
665 (extents) for specified files. This is handy for gaging how
666 "fragmented" a disk volume has become. This is done by simply
671 This would report extents for all files in the current
672 directory for drive B after doing a normal consistency check
673 on drive B. Files which have many extents can be copied and
674 renamed to restore them to a contiguous state, thus improving
675 I/O performance to the files.
677 Previous versions of CHKDSK would simply free
678 allocation units which were marked as used, but were not
679 actually part of any file. CHKDSK 2.00 will recover these
680 "orphan" allocation units if specified. If orphan allocation
681 units are found, CHKDSK prompts for free or recover. Free
682 just frees the orphans as previous versions did, recover will
683 employ allocation chain analysis to create "orphan files" in
684 the root directory of the disk. These files will have the
685 form "%ORPHAN%.l$$" where l will take on some ASCII value
686 greater than '@'. These files may then be inspected to see if
687 valuable data was contained in them. If there is not enough
688 room to make all of the "orphan" files, CHKDSK leaves the
689 unrecovered chains in the FAT so that CHKDSK can be run again
690 (once some entries in the ROOT have been deleted). NOTE:
691 Making ORPHAN files is a SLOW process.
693 Verbose mode. CHKDSK 2.00 may be run with the V switch
694 which causes a trace of the files and directories being
695 processed to be printed as CHKDSK runs.
698 FILTERS FOR MS-DOS 2.0
700 A filter is a utility that reads from standard input,
701 modifies the information in some way, then writes the result
702 to standard output. In this way the data is said to have been
703 "filtered" by the program. Since different filters can be
704 piped together in many different ways a few filters can take
705 the place of a large number of specific purpose programs. The
706 following describes the filters that are provided with MS-DOS
711 Cipher reads a program from standard input, encrypts it
712 using the key word provided by the user, then writes the
713 result to standard output. To decrypt the file simply run
714 CIPHER again using the same keyword. For example:
716 A>CIPHER MYSTERY <NSA.CIA >SECRET.FIL
718 This command line will read file NSA.CIA, encrypt it using
719 the key word "MYSTERY", then write the result to file
720 SECRET.FIL To view the original file the following command
723 A>CIPHER MYSTERY <SECRET.FIL
725 This will read file SECRET.FIL, decrypt the file using the
726 key word "MYSTERY", then write the result to standard output,
727 which in this case is the console.
731 This filter takes as arguments a string and optionally a
732 series of file names. It will send to standard output all
733 lines from the files specified in the command line that
736 If no files are specified FGREP will take the input from
737 standard in. The format for the command line invocation of
740 FGREP [<option>] <string> <filename>*
742 The options available are:
744 /v Will cause FGREP to output all lines NOT
745 containing the specified string.
747 /c Will cause FGREP to only print the count of
748 lines matched in each of the files.
750 /n Each line matched is preceded by its relative
751 line number in the file.
753 The string argument should be enclosed in double quotes.
754 Two double quotes in succession are taken as a single double
757 A>FGREP "Fool""s Paradise" book1.txt book2.txt bible
759 will output all lines from the book1.txt, book2.txt and bible
760 (in that order that contain the string: Fool"s Paradise .
763 A>dir b: | fgrep /v "DAT"
765 will output all names of the files in disk b: which do not
766 contain the string DAT .
770 The filter MORE reads from standard input, sends one
771 screen full of information to standard output and then pauses
776 Pressing the RETURN key will cause another screen full of
777 information to be written to standard output. This process
778 continues until all the input data is read.
782 Sort reads from standard input, sorts the data, the writes
783 the information to standard output. The sort is done using
784 the ASCII collating sequence. There are switches which allow
785 the user to select various options:
787 R - Reverse the sort, that is make "Z" come before "A"
789 +n - Sort starting with column "n" where n is some integer.
790 The default is start the comparisons with column 1,
791 this switch allows the user to start in any column.
795 A>SORT /R <UNSORT.TXT >SORT.TXT
797 This command line will read the file UNSORT.TXT, do a reverse
798 sort, then write the output to file SORT.TXT
802 This command line will cause the output of the directory
803 command to be piped to the sort filter, the sort filter will
804 sort starting with column 14 (This is the column the file size
805 starts), then send the output to the console. Thus a
806 directory sorted by file size will be the result. To get real
809 A>DIR | SORT /+14 | MORE
811 will do the same thing except that MORE will give you a chance
812 to read the directory before it scrolls off the screen.