You may have seen instructions that tell you to “uncomment” or “comment out” lines in a configuration or source code file. This is a simple process, but may not be self-explanatory to people that don’t understand the file’s structure.
您可能已经看到说明,告诉您在配置或源代码文件中“取消注释”或“注释掉”行。 这是一个简单的过程,但对于不了解文件结构的人来说可能并非是不言自明的。
The interpreter ignores lines marked as comments, which are only to aid humans in understanding the file. Because of this, comments can be used to disable or enable configuration options in configuration files.
解释器将忽略标记为注释的行,这仅是为了帮助人们理解文件。 因此,注释可用于禁用或启用配置文件中的配置选项。
简短答案 (The Short Answer)
You can “uncomment a line” in a configuration file by removing the # at the start of the line. Or, to “comment out” a line, add a # character to the start of the line. (Note that some languages have different comment formats, so this may not be true if you’re working with a source code file.)
您可以通过删除行开头的#来“取消注释配置文件中的行”。 或者,要“注释掉”一行,请在该行的开头添加#字符。 (请注意,某些语言具有不同的注释格式,因此,如果您使用的是源代码文件,则可能不正确。)
For example, let’s say you have a file with the following text:
例如,假设您有一个包含以下文本的文件:
# To enable feature X, uncomment the line below
#要启用功能X,请取消注释以下行
#FeatureX = Enabled
#FeatureX =启用
To uncomment the line, you’d remove the # character before it such that the text became:
要取消注释该行,请删除它前面的#字符,以使文本变为:
# To enable feature X, uncomment the line below
#要启用功能X,请取消注释以下行
FeatureX = Enabled
FeatureX =启用
To comment out a line, you’d follow this process in reverse. For example, this text:
要注释掉一行,请按照相反的顺序进行。 例如,这段文字:
# Comment out the line below to disable feature Y
#注释掉下面的行以禁用功能Y
FeatureY = Enabled
FeatureY =启用
Would become:
会成为:
# Comment out the line below to disable feature Y
#注释掉下面的行以禁用功能Y
#FeatureY = Enabled
#FeatureY =启用
Save the configuration file after making these changes.
进行这些更改后,保存配置文件。
什么是评论? (What is a Comment?)
To understand what exactly this means and why we’re referring to “uncommenting” or “commenting out” lines rather than “enabling” or “disabling” them, it’s important to understand the structure of a configuration file. In addition to actual configuration directives, these files can contain comments. These comments aren’t for the computer – they exist to explain the format of the configuration file to anyone reading it. The # before each line tells the computer that this is a comment line – the computer should ignore it, skip over it, and try to interpret the next line that doesn’t begin with a #.
要理解这到底意味着什么,以及为什么我们要引用“取消注释”或“注释掉”行而不是“启用”或“禁用”行,理解配置文件的结构很重要。 除了实际的配置指令外,这些文件还可以包含注释。 这些注释不适用于计算机,它们的存在是为了向任何阅读它的人解释配置文件的格式。 每行之前的#告诉计算机这是一条注释行–计算机应忽略它,跳过它,并尝试解释不是以#开头的下一行。
In some cases, a configuration file may include a configuration option that’s disabled by default. To disable the configuration instruction, a # is included before its line as well, instructing the computer to ignore the line. To enable one of these configuration instructions, all you have to do is remove the # character. To disable any configuration instruction – or add your own comments – just include a # at the start of each line.
在某些情况下,配置文件可能包含默认情况下处于禁用状态的配置选项。 要禁用配置指令,在其行之前还包含一个#,指示计算机忽略该行。 要启用这些配置说明之一,您要做的就是删除#字符。 要禁用任何配置指令(或添加您自己的注释),只需在每行开头添加#。
其他评论格式 (Other Comment Formats)
While this is the format commonly used in configuration files and shell scripts – most notably on Linux and other UNIX-like operating systems – other languages may use other comment formats.
尽管这是配置文件和Shell脚本中常用的格式(最著名的是在Linux和其他类似UNIX的操作系统上),但其他语言也可以使用其他注释格式。
For example, if you’re working with a PHP script, you might see a section like the one below:
例如,如果您使用的是PHP脚本,则可能会看到类似以下内容的部分:
/* This section is commented out by default to avoid causing problems
/ *此部分默认情况下已注释掉,以避免引起问题
to enable feature X, uncomment the section below
要启用功能X,请取消注释以下部分
line of php code
php代码行
another line of php code */
另一行php代码* /
To uncomment the section and enable the feature, you’d change this section to:
要取消注释该部分并启用该功能,请将此部分更改为:
/* This section is commented out by default to avoid causing problems
/ *此部分默认情况下已注释掉,以避免引起问题
to enable feature X, uncomment the section below */
要启用功能X,请取消注释下面的部分* /
line of php code
php代码行
another line of php code
另一行php代码
This is a multi-line PHP comment (C-style comment) where /* begins the comment and */ ends the comment.
这是一个多行PHP注释(C样式注释),其中/ *开始注释,* /结束注释。
翻译自: https://www.howtogeek.com/118389/how-to-comment-out-and-uncomment-lines-in-a-configuration-file/