Description
Windows Terminal version (or Windows build number)
1.7.572.0
Other Software
No response
Steps to reproduce
- Set a system environment variable including
%USERPROFILE%
, e.g.TestVariable
set to%USERPROFILE%\bin
. - In Regedit, confirm that the type is
REG_EXPAND_SZ
by finding it underHKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
. - Start PowerShell or CMD normally, e.g. from the WinX menu, or Shift+RMB in Windows Explorer.
- Print the variable's value, e.g.
echo $env:TestVariable
. - Observe that
%USERPROFILE%
has been expanded, e.g.C:\Users\Chris\bin
is printed. - Open Windows Terminal and create a new PowerShell or CMD tab.
- Print the variable's value, e.g.
echo $env:TestVariable
. - Observe that
%USERPROFILE%
has not been expanded, e.g.%USERPROFILE%\bin
is printed.
Expected Behavior
Like with standalone PowerShell or CMD via CONHOST, the environment variable is properly expanded.
Actual Behavior
The unexpanded value is used.
This isn't happening with every environment variable - others get expanded correctly, like windir
being %SystemRoot%
becoming C:\WINDOWS
. My suspicion is that it's just variables not defined in the system scope not being expanded if they're used in the system scope.
I'm pretty sure this is Windows Terminal doing something weird rather than Windows itself as when viewing the WindowsTerminal.exe
process' environment in Process Explorer, the variables are properly expanded, but when doing the same for the actual shell process, they aren't. If I had to guess, I'd say maybe Windows Terminal is attempting to read the up-to-date environment from the registry when starting new shells instead of letting them inherit its potentially outdated environment, but is doing so inconsistently with how Windows does it. If that's actually what's happening, it may be sensible to use Chocolatey's RefreshEnv batch script or PowerShell module as a reference implementation as that gets the same result as Windows.
This is happening in MSYS-esque Bash shells, too, but the Windows-to-Unix path conversion seems to be doing another round of expansion that masks the symptoms.