DOS Lesson 6: Syntax and Switches; Help System

Syntax

Every command in DOS must be entered in a precise manner, which
is referred to as syntax. Failure to follow the syntax precisely
will most often result in an error message, but in some cases can be disastrous.
So it pays to learn how the syntax works.

  1. First of all is the command name. In previous lessons we listed
    the various internal and external commands that are available to you. In a
    few cases there are shortcut command names, particularly for directory operations.
    To create a directory you could use the command MKDIR, or you could use the
    shortcut MD. Where there are shortcut command names, they are listed in the
    tables in the previous lessons. You must spell the command correctly. Note
    that while I have adopted the convention of typing all command names in capital
    letters, you do not need to do that. In fact, anything you type is converted
    to all capital letters before it is processed, so you do not need to worry
    about case at all. Type everything in lower case letters if you wish, it makes
    no difference.
  2. After the command name you must leave a space! This tells the OS that you
    are finished with the command name and are ready to enter the next part of
    the command. DOS separates the parts of a command with a blank space. That
    is why you could never use blank spaces in file names in DOS and Windows 3.x.
    The OS interpreted the space as a separator between parts of the command.
    Unix still works that way, which is why you must never use spaces in Unix
    file names. You often see the underscore used instead to represent
    a space in a file name.
  3. Next is the drive designation. Drives are represented by letters in DOS,
    though other operating systems have different conventions. In DOS, the first
    two letters, A and B, are reserved for Floppy Disk Drives. Early DOS computers
    (e.g. PC-XT) did not have hard drives, but used two floppy drives instead.
    The first hard drive became the C drive, and so on. That is why most computers
    these days use C for the hard drive even though there is at most only one
    floppy disk drive. Note that drive designations must always be followed by
    a colon.Example: Suppose you are booted and the C: drive is your working directory.
    Your prompt will then look something like

    C:\>

    If you then typed the FORMAT command, you could theoretically wipe out your
    hard drive by formatting it! (Actually, the OS would stop you in this case,
    but you cannot rely on the OS catching all of your errors, so be careful.)
    Now, if you wanted to format a floppy disk, you would insert a disk into your
    floppy disk drive (most likely the A: drive), and you would then type:

    C:\>format a:

    The first part is the command name (FORMAT), followed by a space that tells
    the computer you are finished with the command name, then the drive designator
    a: that tells the OS to apply the command to the A: drive. If you haven’t
    done this before, get a blank floppy disk and try it.

  4. Sometimes you want to operate the command on a directory within a drive.
    You can do this by adding the path you want it to follow. For
    instance, suppose you want to get a directory listing on a directory on your
    hard drive called C:\WP\DOCUMENTS\. You can do this with the following command:C:\>dir c:\wp\documents

    You may not have this exact directory on your hard drive, but pick one you
    do have and try doing a directory command on it.

  5. Sometimes you can modify a command by using what are called switches.
    These modify how the command behaves in some way, and are always shown by
    a preceding forward slash. Switches are the key to making DOS work for you.
    Master the switches and you can do almost anything! For instance, try doing
    a directory command on a large directory, like C:\DOS. You should see everything
    scroll by on the screen very quickly, until it stops with the last screen
    of the directory listing. You will find this hard to use, because it went
    by too fast for you to see most of the listing. But you can change this behavior
    with a simple switch:C:\>dir /p c:\dos

    Note that there is a space between the command name and the switch, and between
    the switch and the path. DOS always expects a space between parts of a command.
    This switch tells the OS to display the results one screen page
    at a time. (The P stands for page here.) The OS will display one page
    of the listing, with a note at the bottom telling you to strike a key to get
    the next page.

  6. Sometimes you want to apply a command to a particular file. You would then
    place the filename in the position of the drive designator/path, or at the
    end, as appropriate. If you just enter a filename without other information,
    the OS will look for that file in the current working directory, then in the
    directories given in the PATH statement. If it does not find it in either
    place, it gives an error statement. But you can give the full path to the
    file and it will be fond if the file is there. For example, if the current
    working directory is C:\DOCUMENTS, and it contained a text file named MYFILE.TXT,
    you could display the contents of that file on your screen with the command:C:\DOCUMENTS\>type myfile.txt

    If your working directory was the root directory C:\, however, and if the
    directory C:\DOCUMENTS was not in the PATH statement, you would get a “File
    not found” error. You could get around this by using the full path:

    C:\>type c:\documents\myfile.txt

  7. So where do you find out the syntax and switches for a DOS
    command? Oddly enough, in the HELP system. DOS comes with a built-in HELP
    system, which you activate by entering the command HELP. If you use the
    command HELP all by itself, you get a list of all the commands available,
    and can then pick the one you want more information about. But you can also
    go directly to the command you want by using the command HELP followed by
    the command name:C:\>help mkdir

    This would give you detailed explanations of how to use the MKDIR command,
    what switches are available, etc. This is a pretty simple command, actually.
    What the HELP system says is:

    *********************************************************************

    MKDIR (MD)

    Creates a directory.

    You can use the MKDIR or MD command to create a multilevel directory structure.

    Syntax

    MKDIR [drive:]path

    MD [drive:]path

    Parameters

    drive:

    Specifies the drive on which you want to create the new directory.

    path

    Specifies the name and location of the new directory. The maximum length
    of any single path from the root directory to the new directory is 63 characters,
    including backslashes (\).

    Related Commands

    For information about deleting a directory, see the <RMDIR> command.
    For information about changing directories, see the <CHDIR> command.

    **********************************************************************

  8. Some HELP system conventions: Note that in the above example, the parameter
    drive was placed within square brackets. This always denotes
    an optional parameter. The command will work perfectly well
    if this parameter is left out. Other conventions include ellipses
    (…), which mean an item can be repeated as often as desired. And items separated
    by a vertical bar (|) are either/or choices. Some examples:TREE [drive:][path] [/F] [/A]

    This means that for the TREE command both the drive and the path are optional,
    and in addition there are two switches, also optional.

    NUMLOCK=[ON|OFF]

    This command can only be used in your CONFIG.SYS file to set whether the numlock
    is turned on or turned off when you boot. Your choices are either ON or OFF,
    obviously.

    PATH [[drive:]path[;…]]

    Remember, the command PATH by itself display the current path, so any drive/path
    specification is optional. If you enter a drive/path, you are changing the
    PATH statement. So the outer set of square brackets makes the whole shebang
    optional. If you do wish to set a path, the drive itself is optional (though
    I have always seen it used. You can add additional directories to the path
    as well, so there is yet another set of square brackets for that. Within those
    brackets are a semicolon, which must be used as a separator between directories
    in a path statement, and then ellipses, which tell you that you can add additional
    directories as needed.

With all of this information, you should now be ready to start using DOS a
little more intelligently. Remember to take a look at the help system, look
for the syntax and switches available, and you too can be a DOS expert.

CC BY-SA 4.0 DOS Lesson 6: Syntax and Switches; Help System by Kevin O'Brien is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.