To comment on the same line as the code you can use &::
or &rem
. You can also use &&
or ||
to replace &
.
Example :
@echo off
echo This is a test &::This is a comment
echo This is another test &rem This is another comment
pause
A curiosity: SET
command allows limited inline comments without &rem
:
set "varname=varvalue" limited inline comment here
Limitations:
- syntax with double quotes
set "varname=varvalue"
orset "varname="
, - an inline comment may not contain any double quote,
- any
cmd
poisonous characters| < > &
must be properly escaped as^| ^< ^> ^&
, - parentheses
( )
must be properly escaped as^( ^)
within a bracketed code block.