2007-08-21

Windows Environment Variables Trap

In Windows, you can easily define environment variables from the "My Computer" icon on your desktop. It's convenient but you can't define the evaluation order, so Windows does it for you but it does it wrongly (at least on Windows XP).

Define these variables:

V1=1
V2=%V1%-2
V3=%V2%-3
V4=4-%V5%
V5=5-%V6%
V6=6

Here is what you get:

V1=1
V2=1-2
V3=1-2-3
V4=4-%V5%
V5=5-6
V6=6


So, V4 was not correctly expanded.
We can also see that the evaluation is partly based on alphabetical order (V1, V2, V3) but that there were 2 passes as V5 is correct.

So, if you want to get safe set an evaluation order on your variables by setting them in your autoexec.bat file.

Aucun commentaire: