Windows bat file comment syntax




















It's used in favor of for comments because , evidently, might not be a valid comment designator in all the shells Configure is intended to support; see line 3. Show 1 more comment. EDIT: modified the example a bit to have it contain the elements you are apparently looking for. Kees Kees 6 6 silver badges 3 3 bronze badges. How can a double-colon line be ignored without being read? Mustn't the interpreter first read the line before recognizing it as a double-colon line? RobKennedy as I read the answer, it does not read anything after the ::, where everything after REM is read.

If the command interpreter stops reading , James, then it would never execute any more of the file. It obviously needs to continue reading to discover where the comment ends and where next line of the file begins.

It has to do that with :: and rem equally. RobKennedy, I also thought it was implied that it only applied to the line the command was on. Show 3 more comments. Multi line comments 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.

And so is this line. And this one Somnath Muluk Somnath Muluk Important: This statement with comment looks intuitively correct: goto error1 :: handling the error but it is not a valid use of the comment. The proof is easy, this goto will not fail either: goto error1 handling the error But similar attempt color 17 :: grey on blue fails executing the command due to 4 arguments unknown to the color command: :: , grey , on , blue.

Community Bot 1 1 1 silver badge. From other answers, it seems that the ampersand is not needed? Snaptastic — The other answers are actually wrong in this point, see my recent edit. This seems to be the correct way; It even gets highlighted as comment in my IDE. In those cases, use REM instead. Pikamander2 Pikamander2 5, 3 3 gold badges 39 39 silver badges 56 56 bronze badges.

This is based on T. Todua's answer. I felt that their answer was good but left out some important details, but they rolled back my edit, so I'm turning my revision into its own answer. In this tutorial, we will look at how to create comments. We will start by showing a single line comment. The comment line will start with rem keyword and we have to put a single space to start the comment part.

In this example, we will write comment This is comment. As we know comments are not executed or interpreted like other commands. They are just text to explain code. It lets you to place a comment in a batch file. REM command is used to document the procedures and functions that you have used in your programs. These are single line comments.

You need to place REM command in front of every comment line. Its syntax is a follows. All the content after REM must be ignored so, the command must be followed by a space or tab character, then follows our comment. Example Here is an example for a single line comment. The below lines are multiple line comments. Now that you are familiar with the syntax, let us try it in practice. We will write a small program to test the comments. As I said above the first line is the comment and the next line prints Hello, World!!!.

The problem with the comments is that though they are ignored by the interpreter, still echoed back to command prompt. When we run the program, we get the output as follows. Hello, World!!!

So, we will try placing the echo off on the first line of program and revise the program. See the output below. Previous Page. Next Page. Previous Page Print Page. Save Close.



0コメント

  • 1000 / 1000