本文翻译自:How to “comment-out” (add comment) in a batch/cmd?

I have a batch file that runs several python scripts that do table modifications. 我有一个批处理文件,它运行几个进行表修改的python脚本。

  1. I want to have users comment out the 1-2 python scripts that they don't want to run, rather than removing them from the batch file (so the next user knows these scripts exist as options!) 我想让用户注释掉他们不想运行的1-2个python脚本,而不是从批处理文件中删除它们(所以下一个用户知道这些脚本作为选项存在!)

  2. I also want to add comments to bring to their attention specifically the variables they need to update in the Batch file before they run it. 我还想添加注释,以便特别注意它们在运行之前需要在批处理文件中更新的变量。 I see that I can use REM . 我看到我可以使用REM But it looks like that's more for updating the user with progress after they've run it. 但看起来更像是在用户运行后更新用户的进度。

Is there a syntax for more appropriately adding a comment? 是否有更适当添加评论的语法?


#1楼

参考:https://stackoom.com/question/lHfW/如何在批处理-cmd中-注释掉-添加注释


#2楼

No, plain old batch files use REM as a comment. 不,普通的旧批处理文件使用REM作为注释。 ECHO is the command that prints something on the screen. ECHO是在屏幕上打印内容的命令。

To "comment out" sections of the file you could use GOTO . 要“注释掉”文件的各个部分,您可以使用GOTO An example of all these commands/techniques: 所有这些命令/技术的示例:

REM it starts here the section below can be safely erased once the file is customised
ECHO Hey you need to edit this file before running it!  Check the instructions inside
ECHO Now press ctrl-c to interrupt execution or enter to continue
PAUSE
REM erase the section above once you have customised the file
python executed1.py
ECHO Skipping some stuff now
GOTO End
python skipped1.py
python skipped2.py
:END
python executed2.py

What can I say? 我能说什么? batch files are a relic of times long gone, they're clunky and ugly. 批处理文件是很久以来的遗留物,它们笨重而丑陋。

You can read more on this website . 您可以在本网站上内容 。

EDIT: modified the example a bit to have it contain the elements you are apparently looking for. 编辑:稍微修改了一下示例,让它包含您正在寻找的元素。


#3楼

The rem command is indeed for comments. rem命令确实用于评论。 It doesn't inherently update anyone after running the script. 运行脚本后,它本身并不会更新任何人。 Some script authors might use it that way instead of echo , though, because by default the batch interpreter will print out each command before it's processed. 但是,一些脚本作者可能会以这种方式使用它而不是echo ,因为默认情况下,批处理解释器会在处理之前打印出每个命令。 Since rem commands don't do anything, it's safe to print them without side effects. 由于rem命令不执行任何操作,因此可以安全地打印它们而没有副作用。 To avoid printing a command, prefix it with @ , or, to apply that setting throughout the program, run @echo off . 要避免打印命令,请在其@echo off加上@ ,或者要在整个程序中应用该设置,请@echo off (It's echo off to avoid printing further commands; the @ is to avoid printing that command prior to the echo setting taking effect.) (这是为了避免打印更多命令而echo off ; @是为了避免在回声设置生效之前打印命令。)

So, in your batch file, you might use this: 因此,在批处理文件中,您可以使用:

@echo off
REM To skip the following Python commands, put "REM" before them:
python foo.py
python bar.py

#4楼

Use :: or REM 使用::REM

::   commenttttttttttt
REM  commenttttttttttt

BUT (as people noted): 但是(正如人们所说):

  • If you use inline, you need to add & character: 如果使用内联,则需要添加&字符:
    your commands here & :: commenttttttttttt
  • Inside nested logic ( IF/ELSE , FOR loops, etc...) use REM because :: gives an error. 嵌套逻辑( IF/ELSEFOR循环等)内部使用REM因为::给出错误。
  • :: may fail within setlocal ENABLEDELAYEDEXPANSION ::可能在setlocal ENABLEDELAYEDEXPANSION失败

#5楼

The :: instead of REM was preferably used in the days that computers weren't very fast. 在计算机不是很快的时候,优选使用::而不是REM。 REM'ed line are read and then ingnored. 读取REM行,然后进行刻录。 ::'ed line are ignored all the way. ::'ed行一直被忽略。 This could speed up your code in "the old days". 这可以加速“旧时代”的代码。 Further more after a REM you need a space, after :: you don't. 在REM之后你需要一个空间,在你不需要之后。

And as said in the first comment: you can add info to any line you feel the need to 正如第一条评论中所述:您可以将信息添加到您认为需要的任何行

SET DATETIME=%DTS:~0,8%-%DTS:~8,6% ::Makes YYYYMMDD-HHMMSS

As for the skipping of parts. 至于零件的跳过。 Putting REM in front of every line can be rather time consuming. 将REM放在每条线的前面可能相当耗时。 As mentioned using GOTO to skip parts is an easy way to skip large pieces of code. 如前所述,使用GOTO跳过部分是一种简单的方法来跳过大量的代码。 Be sure to set a :LABEL at the point you want the code to continue. 确保在希望代码继续的位置设置:LABEL。

SOME CODEGOTO LABEL  ::REM OUT THIS LINE TO EXECUTE THE CODE BETWEEN THIS GOTO AND :LABELSOME CODE TO SKIP
.
LAST LINE OF CODE TO SKIP:LABEL
CODE TO EXECUTE

#6楼

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 : 请参阅Rob van der Woude关于评论块的这篇文章 :

The batch language doesn't have comment blocks, though there are ways to accomplish the effect. 批处理语言没有注释块,但有办法实现这种效果。

 GOTO EndComment1 This line is comment. And so is this line. And this one... :EndComment1 

You can use GOTO Label and :Label for making block comments. 您可以使用GOTO Label和:Label来进行块注释。

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. 或者,如果注释块出现在批处理文件的末尾,则可以在代码末尾写入EXIT ,然后在任何数量的注释中编写,以便您理解。

 @ECHO OFF REM Do something • • REM End of code; use GOTO:EOF instead of EXIT for Windows NT and later EXIT Start of comment block at end of batch file This line is comment. And so is this line. And this one... 

如何在批处理/ cmd中“注释掉”(添加注释)?相关推荐

  1. Eclipse中代码自动添加注释及代码注释模板

    介绍 为了提高代码的可读性以及为了有些代码有洁癖的人的需求,我们要从学生到职业进行迈进的过程中,必须把以前的那种代码可读性不高的习惯改掉,因为我们必须要与企业接轨.. 好了,废话不多说,反正就是提升自 ...

  2. 如何在Eclipse中如何自动添加注释和自定义注释风格

    背景简介 丰富的注释和良好的代码规范,对于代码的阅读性和可维护性起着至关重要的作用.几乎每个公司对这的要求还是比较严格的,往往会形成自己的一套编码规范.但是再实施过程中,如果全靠手动完成,不仅效率低下 ...

  3. Android Studio中xml文件添加注释

    1 xml文件 xml是Extensible Markup Language即可扩展标记语言的缩写.xml文件就是用xml语言编写的文件,用来存储数据.携带数据和交换数据.Android Studio ...

  4. mysql t添加注释_mysql—添加注释(comment)的用法

    在MySQL数据库中, 字段或列的注释是用属性comment来添加. 创建新表的脚本中, 可在字段定义脚本中添加comment属性来添加注释. 示例代码如下: create table test( i ...

  5. python中如何快速注释_python中如何快捷添加注释

    本人使用的编辑器是pycharm,有三种注释方式: 1.用 一对""" 括起来要注释的代码块. 2.用一对'''括起来要注释的代码块. 3.选中要注释的代码,按下ctrl ...

  6. mysql整段注释_MySQL 添加注释(comment)

    如果是已经建好的表, 也可以用修改字段的命令, 然后加上 comment 属性定义, 就可以添加上注释了. 示例代码如下: alter table test change column id id i ...

  7. laravel 框架中使用数据库迁移添加注释

    laravel 框架中数据库迁移添加注释 在使用laravel框架过程中,估计很多人都有用过数据库迁移文件.可能大家都会在建表时为字段添加注释.我在此要说明的是为表添加注释 首先我们需要引入larav ...

  8. python 为html页面增加背景_Python 给html css自动添加注释

    Python 给html css自动添加注释(2020年11月8日) 背景 大二上学期专业开设了网页设计课程,专门学习html和css,有时候也经常有同学找我来帮忙看看他们写的代码,并且改改,我就忽然 ...

  9. C# 如何给现有/新建PDF文档添加注释或标注

    这篇文章主要介绍如何使用免费版PDF组件Free Spire.PDF及C#编程语言给现有PDF文档或新建的PDF文档中的文本添加注释或标注(完整代码附在文章末尾). 首先,下载 Free Spire. ...

  10. PHP被浏览器解释成注释,HTML+CSS入门 在HTML中嵌入的php代码会被浏览器注释掉如何解决...

    本篇教程介绍了HTML+CSS入门 在HTML中嵌入的php代码会被浏览器注释掉如何解决,希望阅读本篇文章以后大家有所收获,帮助大家HTML+CSS入门. < html中嵌入php代码时,没有输 ...

最新文章

  1. 微服务治理实践 | 金丝雀发布
  2. oracle 临时表存在哪里_openGauss魔改PG?它能兼容Oracle的数据库表吗?
  3. 《朝花夕拾》金句摘抄(六)
  4. 深度学习(06)-- Network in Network(NIN)
  5. linux 路由器_为什么我要建立自己的自制Linux路由器
  6. linux7.0下mysql_CentOS 7.0下使用yum安装MySQL
  7. sublime编辑器修改默认的Tab缩进风格
  8. PLC哪些编程软件可以通用?
  9. python机器人编程 乐高_什么是编程?什么是乐高机器人?学习这些有用吗?
  10. 将数组文件转换成bin格式文件
  11. 计算机进化史(纯科普)
  12. 图层蒙版和图层剪贴路径_PS蒙版使用教程、快速蒙版、剪切蒙版、矢量蒙版、图层蒙版要点...
  13. win10更新后应用无法连接服务器,win10更新无法连接到更新服务怎么办_win10无法连接到更新服务的解决方法...
  14. Fortigate 飞塔防火墙命令行常用操作 CLI
  15. 文本分类实战--从TFIDF到深度学习(附代码)
  16. Redis缓存及缓存粒度
  17. 计算机的CPU的电路是多少KW,你的电脑多少瓦? 最全面的CPU功耗测试
  18. 异质性区域下的宏观基本图构建
  19. Git如何回滚代码? 1
  20. 如何高效提高前端代码质量

热门文章

  1. APK反编译工具使用教程
  2. springboot 配置 P6spy
  3. estore简版商城
  4. 腾讯云短信设置流程图文介绍
  5. vscode 离线安装.vsix(window 全教程)
  6. 国内比较有名的maven镜像
  7. ip地址 k8s 显示pod_k8s Pod IP地址规划(CIDR)
  8. HR人事管理系统软件有哪些?如何选择HR人事管理软件?
  9. 学术会议论文查重吗_会议论文需要进行查重吗?
  10. BoundsChecker下载