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.
:: First comment
REM Second comment
Echo Hello REM This remark is displayed by echo
Echo Hello & REM This remark is ignored by echo
Copy work.xls backup.xls &:: We backed up the file
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.
An alternative approach is to use plain text and a goto command to jump execution past the comments:
@Echo OFF Goto :START
Description can go here which can even include - | > characters :START
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:
Echo This example will fail
:: some comment
:NormalLabel & Echo this will not be executed.
:SecondaryLine & Echo This will be executed.
When working within parenthesis/brackets it is safer to use REM for all comment lines.
A comment like the examples below will be interpreted as a command and will produce a fatal error:
or similarly with a variable
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.
Within a registry .REG file comments can be preceded by ;
; Turn the NUMLOCK on at login
There is no valid comment character for FTP but you can cheat by escaping to the shell and running REM
!REM This is a remark
ftp> !REM This is a remark
REM does not set or clear the Errorlevel.
REM is an internal command.
#Now stand in the place where you work,
Now face West
Think about the place where you live, Wonder why you haven't before# - REM 'Stand'
Powershell: # - Comment / Remark.
Equivalent bash command: ### - Comment / Remark.