CmdPi
's answer repeats the received wisdom that Microsoft's command interpreters work like UNIX shells. This is the way that everyone voted with their feet in the 1980s. But in fact they didn't and still don't.
Command names could and can be separated from command tails by a fair number of characters, not solely by whitespace. One can use the equals character, for example, or the comma. path=C:\DOS
is a command and a tail. So too is dir,dos
. Most famously, one can use the full stop. Hence the well-known echo.
trick for echoing a blank line in a command script. What is less well known is that echo;
, echo+
, echo=
, echo(
, echo,
, echo[
, echo]
, echo\
, and echo/
will all do the same (albeit not always for some of them).
In fact, there's a DOS API call (int 21h,ax=6505h
) that can be used to obtain the complete list of characters that are so-called "filename termination characters". And DOS command interpreters use it to determine what characters terminate a command name and begin the command tail. (Microsoft command interpreters for non-DOS operating systems probably just hardwire the set of characters.)
The backslash is one of those characters, and in command interpreters from Microsoft's command
in MS-DOS to Microsoft's cmd
in Windows NT (including IBM's/Microsoft's cmd
for OS/2 along the way) one can execute cd\
and the result will be that the command interpreter changes directory to \
. Whether the termination character is included in the command tail actually varies from command to command. With the cd
command it is. With the dir
and path
commands it is not. (Yes, the command-line parser in Microsoft command interpreters behaves differently according to what built-in command is to be run.)
This has never really been documented, though. As I said: most people voted with their feet in the 1980s to embrace the UNIX shell paradigm, even though things like argument parsing and quoting are a vast conspiratorial fiction implemented not by the command interpreter at all but by the runtime libraries of several programming language implementations for DOS; and you'll find that most of the literature states with confidence that whitespace separates name from tail, even though it isn't actually true. echo.
is usually described a quirk and a trick, and very rarely described as simply one case of an overall syntax that Microsoft's command interpreters have employed for roughly three decades.
I recommend following the 1980s trend here, and not relying upon this little-known syntax. Use whitespace. It's what people document. It's what the likes of IBM and Microsoft themselves document. It's what folk wisdom states to be the case. It's what the UNIX-heads expect. ☺
My command interpreter went with the syntax charts and descriptions that are in the IBM doco. However, you'll find that FreeCOM implements this little-documented behaviour, as do JP Software's command interpreters and the command
from OpenDOS. JP Software's doco recommends using space and describes using other termination characters as "illegal". It is, however, one of the few places that actually states in official documentation that there's an alternative to be had.
Further reading
cmd.exe
is not the same as MS-DOS