Home » Questions » Computers [ Ask a new question ]

How do I do comments at a Windows command prompt?

How do I do comments at a Windows command prompt?

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

Asked by: Guest | Views: 247
Total answers/comments: 2
bert [Entry]

"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"
bert [Entry]

"The REM command only remarks (i.e. Say something as a comment) the line from being executed. However, if @echo off is not in the batch file that line will still echo to the screen.

To prevent these lines from being shown you can do one of three things.

Add @echo off to the batch file:
If you want to hide all commands as well as the REM lines add @echo off as the first line in the batch file.
Change the REM to @REM:
If you want to have the commands shown when the batch file is run, but still want to hide the REM lines type @REM instead of REM.
Use ::(i.e. invalid lable) instead of REM:
Finally, using the :: as the remark command instead of REM also prevents the echo of the remarked line.

source"