44 Votes

Comments in Batch-Scripts (BAT-Files)

Question by Guest | Last update on 2023-11-16 | Created on 2014-10-15

Some of my batch scripts have become longer over time and thus are increasingly confusing for me. That is why, I would like to write some comments to my batch files, so that I can remember what the specific part of the script is doing there.

Is it possible to insert a comment to a BAT-file? All of my previous attempts have only let to error messages because Windows have tried to execute the corresponding line of the script.

ReplyPositiveNegative
3Best Answer3 Votes

When starting a line with REM or :: this line is interpreted as comment.

Here is an example:

REM This is a comment
::This is a comment
:: This is a comment

Please take care of inserting a space or tab after each REM, otherwise it is not working. You do not have to care about this when using the double colon.

Additionally, you have to consider that REM and :: always have to be at the beginning of a line. If you would like to write a comment at the end of a line or after any of your other batch-commands, you can use the following syntax:

command & REM This is a comment
command & ::This is a comment

After a command, you have to use "& REM" or "& ::" to initiate a comment.
Last update on 2023-11-16 | Created on 2014-10-15

ReplyPositive Negative
Reply

Related Topics

Program in ZIP-Folder

Info | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.