在 Bash 中命名常量的约定是什么?

What is a convention for naming a constant in Bash?

在 shell 脚本中,即使我使用 JavaPython 风格的命名约定,我仍然不清楚命名常量。

许多约定建议我使用 "capital letter" 和 "underscore" 一起命名常量,例如MY_CONSTANTPI。但是在Bash中,这可能会与environment variables冲突。

那么,Bash 常量的正确命名约定是什么?

连同您正在 link 提出的问题,Unix 和 Linux 中还有另一个相关问题:Are there naming conventions for variables in shell scripts?

在那里你可以找到几个很好的答案:

Variables that are introduced by the operating system or start up scripts etc. are usually all in CAPITALS, these are called 'envrironment variables'.

To prevent your own variables from conflicting with environment variables, it is a good practice to use lower case.

Shell Style Guide link 一起,您可以在其中找到:

Naming Conventions

Function Names

▶ Lower-case, with underscores to separate words. Separate libraries with ::. Parentheses are required after the function name. The keyword function is optional, but must be used consistently throughout a project.

Variable Names

▶ As for function names.

Constants and Environment Variable Names

▶ All caps, separated with underscores, declared at the top of the file.

man bash 中没有建议的约定,只需注意“小心大写”警告。