Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Doskey works in modern versions of Windows for setting aliases for single commands, e.g. doskey foo=bar.

There's a slight problem trying to use it for compound commands like doskey foo=bar & baz since this gets interpreted as (doskey foo=bar) & baz. The obvious fix would be to add explicit parentheses, doskey foo=(bar & baz) but for some reason this doesn't work, and doskey foo="bar & baz" doesn't work either.

Is there any way of doing this?

share|improve this question
up vote 21 down vote accepted

Escape the ampersand.

foo=bar ^& baz
share|improve this answer

Use $T to separate commands:

doskey foo=bar $T baz
doskey cpdel=copy $1 $2 $T del $1

from doskey /?:

$T     Command separator.  Allows multiple commands in a macro.
share|improve this answer

to add to the previous answers, you can also do this:


    doskey /macrofile=aliases.txt


    foo=bar & baz
    cpdel=copy $1 $2 $T del $1
    cc=echo|set /p=$*|clip

note that in the macrofile, there is no need to escape pipe/ampersand and you can define multiple aliases in one call.

share|improve this answer

To (somewhat) add on to Dennis Williamson's answer, you can also escape the pipe character in order to pipe commands! For example, I wanted a command that copies stuff to the clipboard. Due to the way COPY will interpret it, you need to do a goofy looking command for it to actually copy the text you specify without it being followed by a newline.

In order to define a macro for copying to the clipboard, you can escape the pipe with ^:

doskey cc=echo^|set /p=$*^|clip

Upon execution of the command cc hey, you will now have hey copied to the clipboard!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .