Comments are used to show information in a batch script.
Comments. You can also use |>< ,etc.
REM This is a comment
REMis the official comment command.
::This is a label that acts as a comment
:: comment shown above is not documented as being a comment command, but it is a special case of a label that acts as a comment.
Caution: when labels are used as comments within a bracketed code block or
for command, the command processor expects every label to be followed by at least one command,
so when a jump is made to the label it will have something to execute.
cmd shell will try to execute the second line even if it is formatted as a label (and this causes an error):
( echo This example will fail :: some comment )
When working within bracketed code blocks it is definitely safer to use REM for all comment lines.
It is also possible to use variables as comments. This can be useful to conditionally prevent commands being executed:
@echo off setlocal if /i "%~1"=="update" (set _skip=) Else (set _skip=REM) %_skip% copy update.dat %_skip% echo Update applied ...
When using the above code snippet in a batch file the lines beginning with
%_skip% are only executed if the batch file is called with
update as a parameter.
The batch file format does not have a block comment syntax, but there is an easy workaround for this.
Normally each line of a batch file is read and then executed by the parser, but a
goto statement can be used to jump past a block of plain text (which can be used as a block comment):
@echo off goto :start A multi-line comment block can go here. It can also include special characters such as | > :start
Since the parser never sees the lines between the
goto :start statement and
:start label it can contain arbitrary text (including control characters without the need to escape them) and the parser will not throw an error.
To comment on the same line as the code you can use
&rem. You can also use
|| to replace
@echo off echo This is a test &::This is a comment echo This is another test &rem This is another comment pause
SET command allows limited inline comments without
set "varname=varvalue" limited inline comment here
| < > &must be properly escaped as
^| ^< ^> ^&,
( )must be properly escaped as
^( ^)within a bracketed code block.
<!-- : Comment
This works with both batch script and WSF. The closing tag(
-->), only works in WSF.
|Code||Sucessful in both batch and WSF?|
|False - The closing tag only works for WSF|