Bat file comments line


















Labels, on the other hand, whether valid or not, should always start at the first non-whitespace character in a command line. A true pitfall are code blocks , several commands grouped between parentheses and interpreted as a single command line by CMD.

It turns out that a single :: comment line, immediately followed by a non-blank command line, will work even inside code blocks! Source: a discussion on comment styles on StackOverflow. Replace the double colons by REM statements and these samples will all run without a glitch.

Better still, don't use comments within code blocks at all, but place them just before the code blocks instead:. The 3 code blocks are followed by a fourth "stand-alone" ECHO command. The 3 code blocks are supposed to behave more or less identically, at least in older versions like Windows NT 4 and The code block for comment2 only displays an empty line.

The code block for comment3 is never reached It would seem the code block for comment2 aborts the batch file without warning. Remove that code block, and the rest will be executed as expected. A possible pitfall, pointed out by Joost Kop, is a REM to comment out a line that uses redirection, as in:. In CMD. REM'ed line are read and then ingnored. This could speed up your code in "the old days". Further more after a REM you need a space, after :: you don't.

As for the skipping of parts. Putting REM in front of every line can be rather time consuming. As mentioned using GOTO to skip parts is an easy way to skip large pieces of code. If there are large number of lines you want to comment out then it will be better if you can make multi line comments rather than commenting out every line.

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? Improve this question. Todua See also excellent answers here stackoverflow. Add a comment. Active Oldest Votes. Improve this answer. Todua T.

The double colon :: Is the cleanest. They are just text to explain code. We can also provide multi line or block comment by using multiple rem keyword in a row like below. Below we will use multiple rem keyword which will look like a block of comment but in reality they are multiple single line comments.

We can also use :: as comment sign like rem. We will use :: as line starter and write a comment after that. We can also use it multiple lines for block comments too. Greate post. Keep posting such kind of info on your page.



0コメント

  • 1000 / 1000