How To Comment In Batch File?

Batch files are used to automate command execution and tasks by creating a file with MS-DOS or PowerShell commands. But mainly the MS-DOS commands are popular with the batch file. While creating batch files or batch script some comments will be helpful to explain and detail the script or commands. In this tutorial, we will examine how to comment or comment out in a batch file or batch script.

Rem Instruction To Create Comment

Rem is used to create a single line comment. Every line which starts with the Rem instruction will be interpreted as a comment and this line content will not execute as commands or instructions. As an MS-DOS or batch file is not case sensitive the Rem can be also used as REM or rem even rEM . but the general usage is REM with all capital letters. REM comment lines were especially popular in the old days of the MS-DOS. But REM is a standardized way of creating comments which is defined in MS-DOS.

REM This is line comments

rem This is line comments

:: Command To Create Comment

An alternative to the rem instruction is :: command which can be also used to create comments. Putting the :: two double colons at the start of the line will make this line comment and this line content will not be executed as commands or instructions. Also :: is used to create inline comments with the & sign. :: comment is a non-standard way to create comments and also :: comments are interpreted faster then REM comments.

READ  How To Change Directory In Command-Line or cmd?

Single Line Comment in Batch File or Script

Lets start with simple single or one line comment in a batch or script file. We can use the rem or :: in order to create a single line comment.

dir

REM This single line is comment

mkdir test

:: This line is comment too

Inline Comment

Inline comments are used to execute commands and instructions in the single line but after using the comment sign rem or :: everything is interpreted as comment to the end of line.

dir
 & :: List files and directories

REM This single line is comment

mkdir test
 & :: This is an inline comment

:: This line is comment too

Multi Line Comment in Batch File or Script

REM and :: can be used to create not only single line comments also multiline comments. Actually multiline comments are multiple single line comments where multiple neighbour lines are comments which will look like muıltiline comment.

REM This single line is part of multiline comment
REM This single line is part of multiline comment
REM This single line is part of multiline comment
REM This single line is part of multiline comment
REM This single line is part of multiline comment


:: This single line is part of multiline comment
:: This single line is part of multiline comment
:: This single line is part of multiline comment
:: This single line is part of multiline comment

Leave a Comment