Skip to main content

Batch Script Comments

Batch Script Comments

Comments in Batch Script can be made in two ways:

  • using the Rem statement
  • using the :: statement
note

It’s always a good practice to add comments.

This is useful for script maintenance, to understand what the script actually does.

Comments Using the Rem Statement

Comments in Batch Script can be made using the Rem command.

Any text which follows the Rem statement will be treated as comments and will not be executed.

Rem Example
Rem My comment

where My comment is the comment that needs to be added.

For example, in the following snippet, the Rem command is used to describe what the program does. Notice that the line with the Rem statement will not be executed.

HelloWorld.bat
@echo off 
Rem This program displays Hello World
set message=Hello World
echo %message%
Hello World

Comments Using the :: Statement

The other way to create comments in Batch Script is via the :: command.

Any text which follows the :: statement will be treated as comments and will not be executed.

:: Example
:: My comment

where My comment is the comment that needs to be added.

Like the Rem command, the :: command is used to describe what the program does.

HelloWorld.bat
@echo off 
:: This program displays Hello World
set message=Hello World
echo %message%
Hello World
note

If you have too many lines of Rem, it could slow down the code, because in the end each line of code in the batch file still needs to be executed.