是否有 Unix 配置文件指南
大多数配置文件都是ini 文件(格式:名称=值\n)。是否有关于此问题的任何文档或文章/指南。
或者有人应该善意地遵守这种格式?
Most config files are ini files (format: name=value\n). Is there any documentation or an article/guideline on this matter.
Or is anyone supposed to keep close to this format on good will?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,UNIX 在这个问题上几乎没有做出决定。 格式太多。有了像 Gnome 这样的会话管理器,一些应用程序已经不再维护配置文件,而是将内容保存在 Gnome 注册表 (gconf) 中。
以下是一些一般性观察。
您提到的
ini
格式相当普遍。它确实存在一个问题,您必须采取一些技巧来分配值列表等。但对于大多数情况,它很好,得到良好支持并且广泛可用。UNIX 中使用的大多数格式都依赖于
#
字符来注释该行的其余部分。如果你自己推出一些东西,坚持下去会很好。YAML
是一种人类可读的轻量级格式,您可以使用它(许多应用程序确实使用它,尽管没有我想要的那么多)。有一个约定,所有系统级配置文件都保存在
/etc
中,而用户级配置文件则作为以.
开头的文件保存在用户主目录中(点文件)。某些应用程序(尤其是
Emacs
)将可运行的程序保留为成熟的编程语言作为配置文件。这在不受信任的环境中可能不安全,但在受信任的环境中非常强大且有用。对于新项目,我会将
ini
作为主目录中的.programrc
。unix 编程艺术中有一个有用的部分 关于可能值得您花时间查看的配置格式和文件。
Unfortunately, UNIX is hardly decided on this issue. There are too many formats. With session managers like Gnome, some apps have moved out from maintaining config files to keeping stuff in the Gnome registry (gconf).
Here are some general observations.
The
ini
format you alluded to is fairly widespread. It does have the problem that you'd have to do some tricks to assign a list of values etc. but for most situations, it's fine, well supported and widely available.Most formats used in UNIX rely on the
#
character as commenting the rest of the line. If you are rolling out something by yourself, it would be good to stick to this.YAML
is a human readable lightweight format that you can use (and many apps do use it though not as much as I'd like).There's a convention that all system level config files are kept in
/etc
and user level ones are kept as file starting with.
in the users home directory (dot files).Some applications (notably
Emacs
) keeps a runnable program in a full fledged programming language as it's config file. This might be unsafe in an untrusted environment but very powerful and useful in a trusted one.For a new project, I'd go with
ini
as a.programrc
in the home directory.There's a useful section in the art of unix programming about configuration formats and files that might be worth your while to check out.