As a shell, command.com has two distinct modes of work. First is the interactive mode, in which the user types commands which are then executed immediately. The second is the batch mode, which executes a predefined sequence of commands stored as a text file with the extension .bat. The original concepts for both functionalities is almost certainly derived from the Unix shells, although most programmers would find command.com less able than its counterparts.
Table of contents |
2 Filesystem commands 3 Variables 4 External links |
Syntax
Note that this section does not try to give a full overview to the syntax of command.com, but rather serve as an overview and a mnemonic for the most common and interesting features. Note that all commands are run only after the Enter key is pressed at the end of the line. command.com is case-insensitive, meaning commands can be typed in either case and are all equivalent (so dir, DIR and DiR will all work in the same way).
In order to run a program, simply type the name of its executable and then press "Enter" (it is not necessary to use the extension, e.g. nc.exe can be summoned simply as nc). In order to change the current working drive (see Drive letter assignment), type its letter followed by a colon (D:). Other filesystem commands include:
; DIR : Lists the files in the current directory
; CD, CHDIR : Changes the current working directory or displays the currect directory. CD is best since it is shorter.
; COPY : Copies one file to another (if the destination file already exists, MS-DOS asks whether to replace it). (See also XCOPY, an external command that could also copy directory trees)
; MOVE : The same as COPY, but removes the original afterwards. (MS-DOS 6 and higher).
; DEL, ERASE, DELETE : Deletes a file. DEL is best since it is the shortest. (See also DELTREE, an external command which can delete entire directory trees)
; MD, MKDIR : Create a new directory
; RD, RMDIR : Removes an empty directory
; ECHO : Toggles whether text is displayed (ECHO ON) or not (ECHO OFF). Also displays text on the screen (ECHO text). @ECHO OFF prevents this command from being displayed and only works in a batch file.
; SORT : Sorts the output of another command into a file or the like.
; SET : Sets the value of an environment variable
; PAUSE : Halts execution of the program and displays a message asking the user to press any key to continue.
; SHIFT : Replaces each of the command-line variables with the consequent one (e.g. %0 with %1, %1 with %2 etc. - see below for more information on variables).
; CHOICE : Presents the user with a menu (MS-DOS 6 and higher). Defaults to Y/N.
; CALL : Pauses execution of one batch file, runs another, and returns to the old one and continues.
; COMMAND : The COMMAND command starts a new copy of command.com.
; EXIT : Exits from a new copy of Command.com, or exits the dos prompt in windows.
; VER : This command is built into command.com and displays the current version.
; FOR : Iteration: repeats a command for each out of a specified set of files.
; GOTO : Moves execution to a specified label. Labels are specified at the beginning of a line, with a colon (:likethis).
; REM : Comment: any text following this command is ignored
; IF : Conditional statement, allows to branch the program execution
Filesystem commands
In accordance with command.com's main function as an operating system shell, it includes a number of built-in commands for working with files. Other commands
Note that all commands from the interactive mode can be used in batch files; similarly, one can use batch-file commands directly on the command.com command line, interactively. Therefore, it is impossible to separate the syntax to "interactive" or "batch" commands.Control structures
Control structures are mostly used inside batch files, although they can also be summoned interactively.Variables
Batch files for command.com can be said to have 4 kinds of variables:
See also: List of DOS commands