CMD enviroment variables not expanded in PATH variable

 ̄綄美尐妖づ 提交于 2020-01-03 02:12:38

问题


I've some enviroment variables set in my sistem preferences (Windows 8.1). If i start cmd.exe and execute this commands:

C:\Users\Carlo>echo %GRAILS_HOME%
D:\Grails

C:\Users\Carlo>echo %GRADLE_HOME%
D:\Gradle

C:\Users\Carlo>echo %GROOVY_HOME%
D:\Groovy

C:\Users\Carlo>echo %PATH%
C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\Intel\iCLSClient\;
c:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files (x86)\Brackets\command;%GRAILS_HOME%\bin;%GRADLE_HOME%\bin;
%GROOVY_HOME%\bin

Why the last three variables is not expanded in PATH?

Complete PATH variable is:

C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Brackets\command;%GRAILS_HOME%\bin;%GRADLE_HOME%\bin;%GROOVY_HOME%\bin

回答1:


Environment variables (EnvVars) are simply what their name state: variables; They have a name and a value (in Windows the value is a string).

So in your example the name is PATH and the value is the string you listed. The OS (command interpreter) doesn't have any idea about the semantics of the EnvVar value so when it expands the var name it just shows its value. It doesn't analyze the value and recursively expand any other variables that may be there.

If variables are defined in other variables (something that I wouldn't recommend) is the consumer's job to expand all of them.

A common C function that deals with EnvVars (maybe this will help): ExpandEnvironmentStrings



来源:https://stackoverflow.com/questions/30628678/cmd-enviroment-variables-not-expanded-in-path-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!