[Batch processing bat] Comment a piece of text/string

First, the purpose

Comment string.

2. In the case of echo off

@echo off

2.1 matter

rem off_test_rem

2.2::

:: off_test_::

3. In the case of echo on

echo on

3.1 matter

rem on_test_rem

3.2::

:: on_test_::

4. Phenomena

 Five, the difference

  1. When echo is turned off, the content in both methods is not displayed
  2. When echo is turned on, the content in rem will be displayed, :: still will not be displayed

6. Conclusion

In the bat command, only rem is used as a standard comment command. The logical description of the comment effect caused by double quotes is as follows.

Anything followed by a single colon (:) will be regarded as a label usage. When a single colon is followed by any letter or number, the formed string label can be recognized by goto and call. When a single colon is followed by any special character, it cannot be recognized.

Comments caused by double colons are also implemented based on the latter rule. The following methods can also be used to create comment effects, such as ":.", ":/", etc., but the current convention is to use double colons for comments.

Attached: source code

@echo off
rem off_test_rem
:: off_test_::
%在关闭echo时,两个方法中的内容都不显示%

echo on
rem on_test_rem
:: on_test_::
%在开启echo时,rem中的内容会显示,::仍不会显示%

::注意!本例中为区分注释使用了%[string]%方式,实际使用中不允许使用此方法写注释,因为可能发生不可预料的错误。常用注释方法依然是双冒号。
pause

Guess you like

Origin blog.csdn.net/qq_34217861/article/details/126226686