如何在批处理文件中进行注释?

批处理文件用于通过使用MS-DOS或PowerShell命令创建文件来自动执行命令和任务。但主要是MS-DOS命令在批处理文件中很流行。在创建批处理文件或批处理脚本时,一些注释将有助于解释和详细说明脚本或命令。在本教程中,我们将研究如何在批处理文件或批处理脚本中注释或注释掉。

null

创建注释的Rem指令

Rem 用于创建单行注释。以Rem指令开头的每一行都将被解释为注释,并且这一行内容不会作为命令或指令执行。由于MS-DOS或批处理文件不区分大小写 Rem 也可用作 REM rem 即使 rEM . 但一般的用法是 REM 都是大写字母。REM评论行在MS-DOS的旧时代尤其流行。但是REM是一种在MS-DOS中定义的创建注释的标准化方法。

REM This is line commentsrem This is line comments

●创建注释的命令

rem指令的另一个替代方法是::command,它也可以用来创建注释。将::两个双冒号放在行的开头将使该行成为注释,并且该行内容不会作为命令或指令执行。还::用于创建带符号的内联注释。::注释是创建注释的非标准方式,而且::注释的解释速度比REM注释快。

相关文章: 在Windows中创建符号链接(Symlinks)

批处理文件或脚本中的单行注释

让我们从批处理或脚本文件中的简单单行注释开始。我们可以使用 rem :: 以创建单行注释。

dirREM This single line is commentmkdir test:: This line is comment too

内联注释

内联注释用于在单行中执行命令和指令,但在使用注释符号之后 rem :: 一切都被解释为行末的注释。

dir & :: List files and directoriesREM This single line is commentmkdir test & :: This is an inline comment:: This line is comment too

批处理文件或脚本中的多行注释

REM和::不仅可以用来创建单行注释,还可以创建多行注释。实际上,多行注释是多个单行注释,其中多个相邻行是看起来像mu的注释ı多行注释。

REM This single line is part of multiline commentREM This single line is part of multiline commentREM This single line is part of multiline commentREM This single line is part of multiline commentREM This single line is part of multiline comment:: This single line is part of multiline comment:: This single line is part of multiline comment:: This single line is part of multiline comment:: This single line is part of multiline comment
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享