shell 脚本和 makefile 的命名约定

发布于 2024-08-12 10:13:38 字数 312 浏览 8 评论 0原文

我有一些存储共享变量的 makefile,例如 CC=gcc ,我应该如何命名它们?

候选人是:

common.mk
Make.common
Makefile.common

..哪个更经典?有标准吗?

同样,我有一些 shell 脚本,我应该从以下选项中选择:

do_this_please.sh
do-this-please.sh
DoThisPlease.sh
doThisPlease.sh

这些脚本是否有普遍接受的“大小写”和后缀?

I have a few makefiles that store shared variables, such as CC=gcc , how should I name them?

The candidates are:

common.mk
Make.common
Makefile.common

.. which is more classic? Is there a standard?

Similarly, I have some shell scripts, which should i choose among the following:

do_this_please.sh
do-this-please.sh
DoThisPlease.sh
doThisPlease.sh

Is there a generally accepted 'case' and suffix for these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

つ可否回来 2024-08-19 10:13:38

Google 的开源风格使用下划线作为分隔符: https://google .github.io/styleguide/shellguide.html#s7.4-source-filenames

因此,在您的情况下,它将是使用这种样式的 do_this_please.shdo_this_please

Google's open-source style uses underscores as separators: https://google.github.io/styleguide/shellguide.html#s7.4-source-filenames.

So in your case, it would be do_this_please.sh or do_this_please using this style.

伴随着你 2024-08-19 10:13:38

您所拥有的是将构建粘合在一起的各个部分。构建脚本、自动生成的配置、其他 makefile 包含的 makefile - 质疑这些东西应该如何命名是一个好主意。

最重要的是,保持一致

我见过很多通过 Makefile 包含的文件的 .mk 扩展名。然而,正如 Gyom 所说,这是一个非常主观的问题。

任何能让您选择的编辑器中的语法突出显示满意的东西可能都是一个不错的选择。如果您所在的团队中每个人都使用不同的东西,请询问其他人。对我来说,用 .mk 扩展名命名 makefile include 对每个人来说都是正确的。使用 .sh 后缀命名 shell 脚本也有类似的帮助。

简而言之,使文件名显而易见,并尝试在尽可能多的编辑器/IDE 上进行语法突出显示。 Makefile.common 可能不会这样做,common.mk 可能有更好的办法。

What you've got are the bits that glue a build together. Build scripts, auto-generated configs, makefiles that other makefiles include - questioning how that stuff should be named is a good idea.

Most of all, be consistent.

I've seen a lot of .mk extensions for files included via the Makefile. However, as Gyom suggests, it's a very subjective question.

Whatever makes the syntax highlighter in your editor of choice happy is probably a good choice. If you're on a team where everyone uses something different, ask folks. For me, naming a makefile include with a .mk extension highlights correctly for everyone. Naming shell scripts with a .sh suffix helps in a similar way.

In short, make the file names obvious and try to make syntax highlighting work on as many editors / IDEs as possible. Makefile.common might not do that, common.mk may have a better shot.

甜宝宝 2024-08-19 10:13:38

我会选择do_this_please.sh。这是我的推理:

  • 从可读性的角度来看,间距更可取。这使我们远离了驼峰式。

  • 破折号在大多数 shell 中都有特殊含义,因此漂亮打印词法分析器会在漂亮打印涉及您的文件之一的内容时拾取它并给出奇怪的可视化效果。您会看到上面的一个案例。

这留下了带下划线的版本。其他一些赞成的观点:

  • 此约定与 Python 模块的模块名称相同 (cmp.PEP 8)。 python 中的模块将代码组合在一起。您的 shell 脚本也可以被视为这样的分组。
  • Python 使用者会立即了解您提供的功能的数量和范围。 Python非常流行,它的寄宿起源于脚本,所以它的约定可能是一个很好的模板。

I would go for do_this_please.sh. Here is my reasoning:

  • From a readability perspective, spacing is preferable. This takes us away from the camelcase.

  • The dash has special meaning in most shells, so pretty-print lexers will pick it up and give odd visualisations when pretty-printing something involving one of your files. You see a case above.

This leaves the underscored version. Some additional points in favour:

  • This convention is the same as module names for Python modules (cmp. PEP 8). Modules in python group code together. Your shell script could also be seen as such a grouping.
  • Pythonians will have an immediate idea as to how much and what scope of function you offer. Python is very popular, with its home-stay originating in scripting, so its conventions are probably a good template.
梦开始←不甜 2024-08-19 10:13:38

由于 shell 脚本的目的是执行命令行命令,因此在我看来,shell 脚本的命名约定应遵循文件的命名约定,因为它与操作系统而不是特定的编程语言更相关。由于大多数操作系统使用 -_ 作为单词分隔符,因此最好将脚本命名为 do-this-please.shdo_this_please.sh。我个人使用do_this_please.sh,因为我认为它看起来更好。

我建议始终向 shell 脚本添加 .sh 扩展名,因为如果其他人正在查看您的项目,则在不打开文件的情况下,do_this_please 不会向他们提供有关文件用途的足够信息。另一方面,当他们看到扩展名时,他们知道该文件是一个 shell 脚本,并且看到脚本的名称,他们知道该文件的全部用途,而无需打开它。

Since the purpose of the shell script is to execute command line commands, IMO the naming convention of the shell script should follow the naming conventions for files because it's more related to the operating system rather than a particular programming language. Since most operating systems use - or _ as word separators, it's better to name the script do-this-please.sh or do_this_please.sh. I personally use do_this_please.sh, because I think it looks better.

I would recommend always adding .sh extension to shell scripts, because if other people are looking through your project, do_this_please won't give them enough information about the purpose of the file without opening it. On the other hand when they see the extension, they know the file is a shell script and seeing the name of the script, they know the whole purpose of the file without having to open it.

荒人说梦 2024-08-19 10:13:38

这是一个相当主观的问题,所以我会用主观答案来回答它:-)

恕我直言,请使用 Makefile.commondo-this-please (使用或没有 .sh 后缀)。我已经看过很多次了,它们毫无疑问是可读的。

It is quite a subjective question, so I'll answer it with a subjective answer :-)

IMHO, go for Makefile.common and do-this-please (with or without .sh suffix). I've seen these a lot and they are indisputably readable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文