如何“注释" (添加评论)成批/cmd? [英] How to "comment-out" (add comment) in a batch/cmd?

查看:87
本文介绍了如何“注释" (添加评论)成批/cmd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,该文件运行几个进行表修改的python脚本.

I have a batch file that runs several python scripts that do table modifications.

  1. 我想让用户注释掉他们不想运行的1-2个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!)

我还想添加注释以引起他们的注意,特别是在运行批处理文件之前需要更新的变量.我看到我可以使用REM.但是,这似乎更适合于在用户运行后用进度更新用户.

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. 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?

推荐答案

rem命令确实用于注释.运行脚本后,它不会固有地更新任何人.但是,某些脚本作者可能会以这种方式而不是echo的方式使用它,因为默认情况下,批处理解释器会在处理每个命令之前打印.由于rem命令不执行任何操作,因此可以安全地打印它们而不会产生副作用.为避免打印命令,请在命令前加上@前缀,或者要在整个程序中应用该设置,请运行@echo off. (echo off避免打印更多命令; @避免在回显设置生效之前打印那个命令.)

The rem command is indeed for comments. 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. Since rem commands don't do anything, it's safe to print them without side effects. To avoid printing a command, prefix it with @, or, to apply that setting throughout the program, run @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.)

因此,在批处理文件中,您可以使用以下代码:

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

这篇关于如何“注释" (添加评论)成批/cmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆