Limits on Windows environment variable nesting? Limits on Windows environment variable nesting? windows windows

Limits on Windows environment variable nesting?


It looks like there is a lexicographic dependency on the variables definition.

Windows expands and populates the Enviroment Variables on lexicographic order (:-O)

You can only use on your variable, variables that are "lexicographically" lower than your variable.

Example:Following Definition:

VAR_01=1VAR_02=%VAR_01%-2VAR_03=%VAR_02%-3

Produces

VAR_01 is 1VAR_02 is 1-2VAR_03 is 1-2-3

But

VAR_01=1VAR_02=%VAR_03%-2VAR_03=%VAR_01%-3

Produces

VAR_01 is 1VAR_02 is -2VAR_03 is 1-3

Due VAR_03 is not defined when VAR_02 is expanded.


Yeah, this is driving me crazy. Full repro by:

System Properties, Environment Varialbles, set up like so:

one = c:two = %ONE%\twothree = %TWO%\three

Then click OK, and run cmd. Here's what I see:

C:\>set oneone=C:C:\>set twotwo=C:\twoC:\>set threethree=%TWO%\three

This link explains for Vista, but does not mention that it happens on Win7. http://support.microsoft.com/kb/911089

...Jonas


Have you saved all of the needed variables in the System Variables as well? Because in order to expand the values, the system will have to have a "permanent" memory of all the needed variables.

If you do all these together in a row on the command line, just saying X=something and Y=%X%;else, then when you set the path to PATH=%PATH%;%Y%, the shell expands the values of all the variables before it saves the new value of PATH; but as soon as you close the Command Prompt window, the system has forgotten %X% and %Y% entirely.

However, if you use the System Properties Control Panel to set the PATH to include the unexpanded variables, than all those variables are going to have to exist as system variables when you reboot, or they'll fail to expand.

To ensure that you are saving all the variables in the system so that they are still there after the reboot, either use the System Properties Control Panel or the SETX.EXE command. If you are going to use them in the system PATH (not just your user account's path), then you'll want to use SETX /M X=blah or the bottom part of the System Properties | Environment Variables tab, labeled "System variables".