How to Create DOSKEY Macros in MS-DOS 6.22

In MS-DOS 6.22, the DOSKEY utility itself is the dedicated tool used to recall command-line history, edit input, and create custom command macros. This article explains how DOSKEY functions in MS-DOS 6.22, how to load it into memory, and the exact syntax needed to create, execute, and manage custom macro key combinations.

Loading DOSKEY

DOSKEY is a terminate-and-stay-resident (TSR) program included with MS-DOS 6.22. Before creating macros, you must load the utility into system memory by typing the following command at the prompt:

DOSKEY

To save conventional memory, you can load it into upper memory blocks via your AUTOEXEC.BAT file:

LH DOSKEY

Creating Macros

Once DOSKEY is active, you can define macros directly from the command prompt. A macro functions like an in-memory batch file that executes much faster because it does not require reading from disk.

The basic syntax for defining a macro is:

DOSKEY macroname=command

For example, to create a shorthand command named ls that mimics the Unix directory listing using the DOS DIR command:

DOSKEY ls=DIR /W

Using Special Macro Codes

DOSKEY provides special dollar-sign ($) codes to handle command chaining, arguments, and redirection:

  • $T (Command Separator): Allows running multiple commands within a single macro.
    • Example: DOSKEY wipe=CLS $T DIR (Clears the screen, then displays the directory).
  • $1 through $9 (Positional Parameters): Represents command-line arguments passed to the macro.
    • Example: DOSKEY cdc=CD \$1 $T DIR
  • $* (All Parameters): Passes all arguments typed after the macro name to the command.
    • Example: DOSKEY mtype=TYPE $* $T PAUSE
  • $G and $L (Redirection): Replaces the standard > (greater than) and < (less than) redirection operators.
  • $B (Pipe): Replaces the standard | (pipe) operator.
    • Example: DOSKEY dirmore=DIR $B MORE

Managing and Deleting Macros

  • View all active macros: Enter DOSKEY /MACROS (or DOSKEY /M).
  • Delete a specific macro: Assign the macro name to nothing: DOSKEY macroname=.
  • Clear all macros: Press ALT + F10 while at the command prompt.

Saving Macros Permanently

Because DOSKEY macros reside purely in RAM, they disappear when the system restarts. To preserve your macros, save them to a batch file using redirection:

DOSKEY /MACROS > MACROS.BAT

Edit MACROS.BAT to prepend DOSKEY to each line, then call CALL MACROS.BAT from your AUTOEXEC.BAT file so your custom shortcuts load automatically during boot.