How to comment in batch file


















Can I have some comments in batch file list? Batch files traditionally allow single line comments only. The REM command stands for remark. 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. What commands are available in a batch file?

The commands in a batch file are executed by a special interface or shell. A batch script can be created using any text editor such as Notepad or WordPad , and must be saved only in plain text format. What is the purpose of creating batch files? There are two ways to create comments in Batch Script; one is via the Rem command. Any text which follows the Rem statement will be treated as comments and will not be executed.

Following is the general syntax of this statement. The above command produces the following output. You will notice that the line with the Rem statement will not be executed. 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. Output Hello, World!!! Press any key to continue. There are some situations where you need to keep echo command in on state.

During such cases, the comments are also echoed back on the screen. So, we will try to solve it by revising the program. This program gives the output same as the program version 3, But illustrates a different type of comments.

You may also include these type of comments in your batch file if feel bored with REM command. REM command must be followed by a space or tab character. You may include any symbol in the comments without any restriction. Otherwise, it is ignored.

You can also place a comments in a batch file by starting the comment line with two colons [::] as shown below. This is the basic syntax for multiple line comments. Every line may be replaced with comments.

Hence we allow multiline comments without having to use REM command before each line. Try it out yourself! If you have a remark using the double-colon :: style inside of a FOR loop it can lead to problems, while REM never will.



0コメント

  • 1000 / 1000