linux - Linux 环境变量名称中允许的字符

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/

相关文章:

linux - 如何通过脚本创建 crontab

python - 你如何在 django 网站上记录服务器错误

linux - 递归列出目录中的所有文件,包括符号链接(symbolic link)目录中的文件

python - 如何实现有序的默认字典?

python - 在 Pandas 中附加到一个空的 DataFrame?

python - 如何使用 python smtplib 向多个收件人发送电子邮件?

python - pip 相当于 `npm install package --save-dev`

python - 如何打开一个文件进行读写?

linux - 如何在 Linux 中永久导出变量?

linux - 如何使用 sed 删除文件的最后 n 行