Batch Script Comments - Batch Script

What is the need of Comments in Batch Script?

Adding comments or documentation for the scripts which are created helps in understanding what the script actually does thereby facilitating easy maintenance of the scripts.
If the following piece of code has no form of comments, an average person who has not developed it, trying to understand the script would take a lot of time to understand.

How to create comments in Batch Script

Method 1: Comments Using the Rem Statement

Any text which follows the Rem statement will be treated as comments and will not be executed.
Syntax
where ‘Remarks’ is the comments which needs to be added.
Example
Output
The above command produces the following output. You will notice that the line with the Rem statement will not be executed.

Method 2: Comments Using the :: Statement

Any text which follows the :: statement will be treated as comments and will not be executed.
Syntax
where ‘Remarks’ is the comment which needs to be added.
The following example shows a simple way the Rem command can be used.
Example
Output
The above command produces the following output. You will notice that the line with the :: statement will not be executed.
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.
Recall the example at the beginning and let us see how it looks when documentation is added to it.

After adding documentation, this code has become more understandable to users who have not developed the code and hence is more maintainable.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Batch Script Topics