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

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

问题描述

我有一个批处理文件,它运行多个执行表修改的 python 脚本.

  1. 我想让用户注释掉他们不想运行的 1-2 个 python 脚本,而不是从批处理文件中删除它们(所以下一个用户知道这些脚本作为选项存在!)

  2. 我还想添加注释以特别提醒他们注意在运行批处理文件之前需要在批处理文件中更新的变量.我看到我可以使用 REM.但看起来这更多是为了在用户运行后更新进度.

是否有更恰当地添加评论的语法?

解决方案

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

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

@echo offREM 要跳过以下 Python 命令,请将REM"放在它们之前:蟒蛇蟒蛇酒吧.py

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

  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!)

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

解决方案

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天全站免登陆