I'm trying to get a handle on how you know if an expandable string will be properly expanded in a user's
Path environment variable.
As there appears to be a lack of proper documentation on the MS website(these are the closest I can find; SE threads here and here also apply), my questions (and observations) can be categorized as follows.
- MS documents that it can be a String, Expandable String, or Multistring.
- Default appears to be standard String.
- If multistring, only the first string is recognized.
- My system seem to periodically revert to a standard string after expanding variables first (with fixed values) from an expandable string.
- I am unsure if it is Microsoft Updates or rogue installers that are changing the type back to standard String.
Environment variable expansion layers
- How many layers of variable expansion can I rely on?
This SE thread seems to indicate that it's unpredictable.
- Right now I have
Path=%A_ProPath%where A_ProPath is another expandable string that begins
- If however, inside %_SysPIntel% I refer to %_Intel_SW% (C:\Program Files (x86)\IntelSWTools), that's not being expanded.
- Right now I have
- I was getting different results if I had a variable type set to expandable, but without any
%var%references inside vs. just setting the variable type to standard string. It seems that references to standard strings are more often being expanded than references to expandable strings. Why is this?
- How many layers of variable expansion can I rely on? This SE thread seems to indicate that it's unpredictable.
Expansion sequence of Expandable strings
- Variable expansion is not recursive, so there don't appear to be any issue with cyclic references
- Expansion seems only to proceed in alphabetical order, and only as a single pass (per level: system and then user).
- Order that you add or edit variable values does not appear to matter
- Variables are case-insensitive
Pathin your System Variables is the same as
%path%in a command prompt window).
I don't know if they are all converted to a single case before alphabetization.
I believe I started doing
_to lead off my variable names because any values were alphabetically after Path weren't expanding in my Path, but this would suggest that you can't use %SystemRoot% or %WinDir% directly in a Path. Does this make any sense?
Assuming environment variables are expanded in order of their alphabetic appearance, I further assume environment variables are case insensitive. But when sorting vs non-alphabetic characters, are environment variables evaluated as if any letters are lowercased and then compared by ascii value (e.g. perlre
[0-9\- _]all occur before a-z)? or uppercased before ascii comparison (
_comes after the alphabet)?
What is the set of acceptable characters used within variable names? Can
~(), etc be used?
If there's a System environment variable called PATH, and a user PATH, which is evaluated first? Can my user PATH make reference to system-level custom variables?