Why is the syntax for touching a file from the command prompt so strange?

Raymond Chen

Raymond


The magic incantation for updating the last-modified date on a
file

is

COPY /B FILE+,,

What strange syntax!
What’s with the plus sign and the commas, anyway?

The formal syntax is the much more straightforward

COPY /B A+B+C+D

This means to start with the file A,
then append the files B, C, and D,
treating them all as binary files.

If you omit the
B+C+D part,
then you get

COPY /B A+

This means
“Start with A, then append nothing.”
The side effect is that the last-write time gets updated,
because the command processor opens A for append,
writes nothing,
then closes the handle.

That syntax has worked since at least MS-DOS 2.1
(the earliest version I still have a virtual machine for).

I dont know where the two-comma version came from,
but it most likely exploited a parsing glitch in
COMMAND.COM,
and somehow this variant gained traction and
became the version everybody used
(even though the other version is two keystrokes shorter).
As a result, this weird syntax has become grandfathered
as a special-case in the CMD.EXE parser.
Here’s some actual code from the part of
CMD.EXE which parses the arguments to the
COPY command:

if (parse_state == SEEN_TWO_COMMAS)
    copy_mode = TOUCH;
Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.