-1

I need help settling a discussion about comments in configuration files. This is about the question "what dictates which character/string is used for commenting in any given program?"

Theory A) states that this is at the discretion of the program's developer. While it is widespread practice in programs under Unix-like OSs that the # charcter be used for commenting in config files (examples: ssh config files, /etc/fstab etc etc.), anyone may just as well specify in a new application that in the config files used by that application, a //, ++ or any other string constitutes the beginning of a comment.

Theory B) states that the above-mentioned widespread practice of using # is actually mandatory in that config files are like Bash scripts, and hence the syntax valid in bash scripts dictates, in some way (maybe by a standard, or some OS-wide directives), that the same syntax be applied also to config files of any programs - and that is the reason why # is the comment character in most config files.

Theory C) states that some entirely different factors dictate which string is used for commenting in config files (please specify).

The following seems to point at theory A):

many different configuration-file formats exist, with each application or service potentially having a unique format.

, but it's not an explicit answer. Thanks for any hints, also sources will be much appreciated!

  • 1
    What is a comment depends entirely how the config is parsed. So A) – Panki Nov 5 '19 at 10:58
  • Panki, since you are answering, wanna write that in the answers section? Any sources? – Bennypr0fane Nov 5 '19 at 11:02
  • This is way too little to count as an answer. Source is my personal experience and common sense... if you develop a program, you decide what language your config uses (an .INI, a bash compatible file, a .YAML file, something completely different that doesn't even allow comments...) – Panki Nov 5 '19 at 11:05
  • "but I wanted to get other opinions." This is not the goal of stackexchange. The goal here is to be able to produce quality Q/A leaded by facts, not opinions. Your questoin has no real answer. – binarym Nov 5 '19 at 11:08
  • You could (almost) use : as a comment pair (colon, space) in shell scripts. – roaima Nov 5 '19 at 20:34
5

The program that reads the config file is free to do whatever it wants with the file's contents. That is, it's totally up to the whims of the programmer. There's nothing that separates a configuration file from any other data file, most of which are at least somewhat application-specific. So, if I wanted, I could make the letter a a comment marker, or declare that a non-space character in a particular column marks a comment (like in old versions of Fortran).

That said, both of those would be wholly unexpected for any user, so it would be better to use # or some other commonly used character (like ;). But the reason to use # is only because of the fact that it's common, not because Bash (or any shell) has anything to directly do with it.

In general, most configuration files aren't scripts, even though they may contain assignments like in scripts, or C-style brace blocks ({ ... };). That's good for simplicity, but perhaps not for those really extreme cases where you need to do something terribly complex.

But in some cases a configuration file can actually be a Bash script, or Javascript code, or Lua code, or Python code, or whatever. For example, the files in /etc/default/ in Debian are shell scripts, they're read by the init scripts of various programs (in pre-systemd times anyway). And if your program is implemented in Lua, reading a Lua script as a configuration file is extremely simple to implement.

4

There's no category called "configuration files", each program and, by extension, each programmer is free to use whatever they like. I don't know of any sources, but I can give you some examples of config files that use various characters (just picking one random example per category):

  1. #: /etc/nfsmount

  2. ;:/etc/php/php.ini

  3. %: /etc/slsh.rc

  4. //: /etc/java11-openjdk/security/policy/unlimited/default_local.policy

These are just the ones I found after a quick look in /etc. I'm sure you'll also find python-style configuration files somewhere where comments can be either # or just """.

So no, there is no hard rule, everyone does as they like, but many default to #.

  • Look further under /etc/systemd and you will find files that use two of those. (-: UCL configuration files have single line and multiple line comment forms, moreover. – JdeBP Nov 14 '19 at 20:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.