Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What's the equivalent of # for Windows cmd console sessions, to create a comment?

The operating system is Windows XP.

share|improve this question
1  
Note that cmd.exe in Windows is not DOS - it's a full Windows application which just has a similar syntax to that of command.com –  grawity Dec 12 '09 at 11:53

3 Answers 3

up vote 25 down vote accepted

REM is the standard way:

REM this is a comment

You could also use the double-colon convention commonly seen in batch files:

:: another comment

A single colon followed by a string is a label, but a double colon and anything after it are silently ignored. One could argue that this form is more legible than the REM command.

Note that both of these methods only work at the beginning of a line. If you want to append a comment to a command, you can use them with the command concatenation character (&), like this:

dir & REM a comment
dir &:: another one
share|improve this answer
1  
Thanks. Does this only work if it's the first thing encountered, as opposed to doing something like dir :: comment? –  Andrew Grimm Dec 12 '09 at 9:53
    
@Andrew Grimm, good point. See my update. –  efotinis Dec 12 '09 at 10:16
    
First an useful link. Then, double colon comments doesn't seem to work inside code blocks (code between parentheses, like in if/for loops). –  x-yuri Jun 20 at 11:54

You prefix your comment with the word REM.

REM This is a comment.

But if you want your comment printed back to you, you should echo it:

echo This is a comment you'll see.
share|improve this answer
    
Accepting as working, but I'd only have been slightly more surprised if the answer was BTW, like in lolcode.com/specs/1.2#comments –  Andrew Grimm Dec 12 '09 at 8:06

I believe the answer provided by bernhard is incorrect.

At least through win 7,

rem comment

in a batch file will print in the output. To suppress printing, use

@ rem comment

or

@rem comment

The same goes for other commands, which by default are echoed to the console.

share|improve this answer
    
The command REM comment will not print any output to the screen. For a live demonstration, open a Command Prompt and run echo comment then run the command rem comment. Notice that the echo command prints output to the screen while the rem command did not. –  Twisty Nov 22 at 21:52
    
I always use @REM comment in my batch scripts to avoid them showing up. I would have suggested editing Bernards answer to include using @ before REM in batch scripts to avoid it showing up rather than posting a whole new answer. –  Robin Hood Nov 22 at 22:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.