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可能不支持除字母,数字和下划线之外的任何内容.