rem is a command
rem
is a «real» built-in command.
This can be demonstrated with the following simple batch file:
- The
/?
is not interpreted as comment but rather as a request for help on rem
.
- The
echo
command is ended with the &&
and, if successful, the next command (rem
) is evauluated.
@rem /?
@echo hello world && rem because rem is a command, in can be put in a command series with the ampersand
When executed, the batch file prints:
Records comments (remarks) in a batch file or CONFIG.SYS.
REM [comment]
Using double colons
An unofficial (and sometimes problematic) way to comment lines is to use double colons (::
) because it might be visually easier to read.
@echo off
rem This is a real comment
echo One
:: These lines are not interpreted/parsed and
:: thus might serve as comments.
echo Two
A particular problem of ::
occurs when used within ( … )
:
@echo off
if exist double-colons-problem.bat (
rem Notify the user that double-colon-problem.bat was found
echo The file double-colons-problem.bat was found
) else (
echo The file double-colons-problem.bat was not found
:: This «comment» causes the error «) was unexpected at this time.»
)