MS-DOS 6.22 DOSKEY: Create Command Line Macros

In MS-DOS 6.22, the built-in utility used to create custom macro keys and command-line shortcuts is DOSKEY. This article provides a straightforward guide on how to load the DOSKEY terminate-and-stay-resident (TSR) program, define simple and complex macros, pass arguments, and ensure your shortcuts remain active across reboots.

Loading DOSKEY

Before creating macros, you must load the DOSKEY utility into memory. At the DOS prompt, type:

DOSKEY

Once executed, DOSKEY resides in memory for your current session, enabling command history recall and custom macro definitions.

Basic Macro Syntax

To define a custom macro, use the following syntax:

DOSKEY macroname=command

For example, to create a shortcut named ls that executes the standard DOS directory listing in wide format:

DOSKEY ls=dir /w

Typing ls at the prompt will now execute dir /w.

Chaining Commands and Special Characters

Standard redirection and piping symbols (|, >, <) cannot be typed directly into a DOSKEY definition because DOS interprets them immediately. DOSKEY provides special codes instead:

  • $T: Separates multiple commands within a single macro.
  • $G: Redirects output (equivalent to >).
  • \(G\)G: Appends output (equivalent to >>).
  • $L: Redirects input (equivalent to <).
  • $B: Pipes output (equivalent to |).

For example, to create a macro named cleanup that deletes temporary files and then clears the screen:

DOSKEY cleanup=del *.tmp $T cls

Passing Arguments

You can pass parameters to your macros using numbered placeholders or a catch-all variable:

  • $1 through $9: Represents the first through ninth command-line argument.
  • $*: Represents all arguments passed after the macro name.

For example, to create a shortcut named mcd that creates a new directory and immediately navigates into it:

DOSKEY mcd=md $1 $T cd $1

Running mcd project will execute md project followed by cd project.

Managing and Deleting Macros

  • View all active macros:
    DOSKEY /MACROS
  • Clear a specific macro: Assign the macro name to nothing:
    DOSKEY ls=
  • Clear all macros: Press Alt + F10 at the command line.

Making Macros Persistent

Macros stored in DOSKEY disappear when the computer restarts. To make your custom shortcuts permanently available, add the DOSKEY commands directly into your AUTOEXEC.BAT file:

C:\DOS\DOSKEY
DOSKEY ls=dir /w
DOSKEY cleanup=del *.tmp $T cls
DOSKEY mcd=md $1 $T cd $1