How to add remark in batch file
See this post by Rob van der Woude on comment blocks :. The batch language doesn't have comment blocks, though there are ways to accomplish the effect.
Or, If the comment block appears at the end of the batch file, you can write EXIT at end of code and then any number of comments for your understanding. It works only because goto ignores all arguments past the first one. The proof is easy, this goto will not fail either:. This is an old topic and I'd like to add my understanding here to expand the knowledge of this interesting topic.
We can treat :: as a token that as soon as CMD parser encounters the first non-blank space in a line is this :: token, it will just skip the whole line and read next line. That's why REM should be followed by at least a blank space to be able to function as a comment for the line, while :: does not need any blank space behind it.
When commenting, use :: as it's 3 times faster. An example is shown here. Only if comments are in if , use rem , as the colons could make errors, because they are a label. For commenting line use REM or :: though :: might fail inside brackets. As noting will be parsed after the exit command you can use it to put comments at the end of the file:. More details here :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. Ask Question. Asked 9 years, 6 months ago. Active 3 months ago. Viewed 1. I have a batch file that runs several python scripts that do table modifications. Is there a syntax for more appropriately adding a comment? Todua See also excellent answers here stackoverflow. Add a comment. Active Oldest Votes.
Todua T. The double colon :: Is the cleanest. And it can be used at the start or middle of a line! Didn't work for me when done inline like this. To illustrate, open cmd prompt and run dir ::blah which doesn't list the contents of.
Examples of how using :: labels as comments can cause difficult-to-anticipate errors. Show 13 more comments. Rob Kennedy Rob Kennedy k 20 20 gold badges silver badges bronze badges. It is one of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run. Brent81 I feel this should be the correct answer. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. Records comments in a script, batch, or config. If no comment is specified, rem adds vertical spacing. The rem command doesn't display comments on the screen. To display comments on the screen, you must include the echo on command in your file. In fact the CMD shell will attempt to execute the second line even if it is formatted as a label.
Anything which is not a valid command, even a blank line or a closing parenthesis will cause a :: style comment to fail:. The line above is equivalent to: REM The REM wipes out everything following, including the close bracket which will typically break the script.
This behaviour is a result of the batch parsing rules used by CMD. EXE and so is unlikely to ever change. We have covered adding a whole line comment and adding a comment at the end of a line, but sometimes there is a need to add a small comment in the middle of a line to explain some detail. Batch variable names can contain spaces and punctuation, we can take advantage of this fact by typing our comment as a non-existent variable.
0コメント