Linux 环境变量名称中允许使用哪些字符?我对手册页和网络的粗略搜索只提供了有关如何使用变量的信息,但没有提供允许使用哪些名称的信息。
我有一个 Java 程序,它需要一个包含点的已定义环境变量,例如 com.example.fancyproperty
。在 Windows 中,我可以设置该变量,但我没有在 linux 中设置它(在 SuSE 和 Ubuntu 中尝试过)。是否允许使用该变量名?
最佳答案
来自 The Open Group :
These strings have the form name=value; names shall not contain the character '='. For values to be portable across systems conforming to IEEE Std 1003.1-2001, the value shall be composed of characters from the portable character set (except NUL and as indicated below).
所以名称可以包含除 = 和 NUL 之外的任何字符,但是:
Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. Other characters may be permitted by an implementation; applications shall tolerate the presence of such names.
因此,虽然名称可能有效,但您的 shell 可能不支持除字母、数字和下划线之外的任何内容。
https://stackoverflow.com/questions/2821043/