REM – Windows CMD Command

In a batch file REM at the start of a line signifies a comment or REMARK, alternatively adding :: at the start of a line has a similar effect.

Although you can use Rem without a comment to add vertical spacing to a batch file, you can also use completely blank lines. The blank lines are ignored when processing the batch program.

The double-colon is not documented as a comment command, it is a special case of a label that acts as a comment. An important limitation of this is that as a label it can only be used at the beginning of the line.

Comments within bracketed code blocks.

When labels are used as comments within a bracketed code block or FOR command, the command processor will expect (not unreasonably) that every label is followed by at least one command. (That way if you jump to the label it will have something to execute.) In fact the CMD shell will attempt to execute the second line even if it is formatted as a label:

When working within parentheses/brackets it is safer to use REM for all comment lines.

Bugs

A comment like the examples below will be interpreted as a command and will produce a fatal error:
::%~
or
REM %~

or similarly with a variable
set var=demo
rem %var:=
or
rem %var:*=

There errors will terminate all further batch processing and return an error message:
The following usage of the path operator in batch-parameter substitution is invalid: %~

This behaviour is a result of the batch parsing rules used by CMD.EXE and so is unlikely to ever change.

A REM comment can be significantly slower to process than ::
In Windows NT 4 the REM comment would incorrectly reset the %errorlevel% to 0.

To avoid these issues, make sure your comments do not contain % chars or any redirection operators.

Registry Comments

Within a registry .REG file comments can be preceded by ;

FTP Comments

There is no valid comment character for FTP but you can cheat by escaping to the shell and running REM
e.g.

REM does not set or clear the Errorlevel.
REM is an internal command.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *