Windows环境变量名称和值的有效字符是什么? [英] What are valid characters for Windows environment variable names and values?

查看:173
本文介绍了Windows环境变量名称和值的有效字符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一番研究,我发现长度对于名称的限制为255,值为32767个字符。



但是允许哪些字符用于名称

允许哪些字符

解决方案

关于变量值:字符作为变量值,包括空格。如果使用特殊字符<>,|,&或^,则必须先使用转义字符(^)或引号。如果使用引号,它们将作为值的一部分包含在内,因为将等号后的所有值作为值。



http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true



查看设置环境变量一节。



关于变量名:在我看来,为了与每个应用程序的最佳兼容性,您应该限制自己字母,数字,下划线(_)和减号( - )。



我确信文件的所有POSIX有效字符都可以,但是我没有找到任何






关于变量名称,我们还需要接受括号,因为%ProgramFiles x86)%是一个着名的envar。从我的实验看,除了字母和数字字符之外,这些字符似乎是有效的 _(){} [] $ * + - \ /\"#',;.@!?并且这些字符无效%<> ^& | =:



我没有做一个详尽的搜索,只是测试了最常见的非字母数字字符。



只是为了乐趣,你可以命名一个envar %_(){} [] $ * + - \ /\"#',;.@!?%

  C:\> set _(){} [] $ * +  -  \ /\"#',;.@!?= xyz 

C:\\ \\ echo $ _ + p>

After some reseach, I found out that length limits for names are 255 and for values 32767 characters.

But which characters are allowed for names?
And which characters are allowed for values?

解决方案

About variable values: you can use most characters as variable values, including white space. If you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true

Check section "Setting environment variables".

About variable names: in my opinion, for best compatibility with every application, you should limit yourself to letters, numbers, underscore (_) and minus (-).

I'm quite sure that all POSIX valid characters for files are ok, but I did not found any evidence of this.


Concerning variable names names we need to also accept parenthesis since %ProgramFiles(x86)% is a well-known envar. From my experiments it seems that in addition to letters and digits characters, these characters are valid _(){}[]$*+-\/"#',;.@!? and these characters are not valid %<>^&|=:.

I didn't do an exhaustive search but just tested most common non alphanumeric characters.

And just for the fun of it you can name an envar %_(){}[]$*+-\/"#',;.@!?%:

C:\>set _(){}[]$*+-\/"#',;.@!?=xyz

C:\>echo %_(){}[]$*+-\/"#',;.@!?%
xyz

这篇关于Windows环境变量名称和值的有效字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆