Repository navigation
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aOS-WSLResolution-ExternalThe issue is caused by external component(s).WG-Enginecore PowerShell engine, interpreter, and runtime
Description
I just upgraded to pwsh 7 in my WSL instance and it causes the process to exit when using windows integration of $PATH with an error of: bad variable name: (x86)\Nvidia
It persists even after removing this folder from my windows path (the next error is about a bad variable for Files/Microsoft. This only occurs when starting a fresh WSL instance and doesn't occur when running pwsh from bash.
Changing HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{YOUR_GUID}\Flags to 5 will disable the integration and fix this behavior.
Changing the above registry key to 7 (enable integration) and using bash as your shell will also fix this behavior.
Steps to reproduce
- set your WSL shell to pwsh 7 with:
chsh -s /path/to/pwsh - Make sure windows integration of path is enabled in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{YOUR_GUID}and theFlagskey is set to 7. Setting this key to 5 turns the integration off and pwsh will start fine. Additionally setting this back to 7 and setting bash as your shell will have WSL start fine as well. - Restart WSL and the path should fail (depending on your windows path of course).
Expected behavior
Path should be properly parsed.
Actual behavior
Failures related to bad variable names.
Environment data
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Linux 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reacted by Michael Klement, ExE Boss and Fabien Barbier
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aOS-WSLResolution-ExternalThe issue is caused by external component(s).WG-Enginecore PowerShell engine, interpreter, and runtime
Activity
iSazonov commentedon Mar 5, 2020
I think it is a problem with Windows paths sharing.
See microsoft/WSL#1640.
Steve Lee (@SteveL-MSFT) Rob Holt (@rjmholt) Sean Wheeler (@sdwheeler) I believe this is "by-design" and the workaround could be documented.
gdoenlen commentedon Mar 5, 2020
Yes I know it's from path sharing, hence the registry edits. The work around isn't ideal as you lose access to everything in windows without typing the full path to something (i.e. vscode). Pwsh 6 definitely didn't have the same behavior.
rjmholt commentedon Mar 5, 2020
It’s a known issue arising from the fact that 7, unlike 6, supports being run as a login shell.
This has shed new light on it though
iSazonov commentedon Mar 5, 2020
Rob Holt (@rjmholt) Is it WSL or PowerShell issue? I did not find we parse PATH in the code.
rjmholt commentedon Mar 5, 2020
Quite possibly a PowerShell issue.
execcares about the path. We use it here:PowerShell/src/powershell/Program.cs
Lines 325 to 330 in 348ca85
iSazonov commentedon Mar 5, 2020
Rob Holt (@rjmholt) You referenced MacOs code :-).
In any case we don't get explicitly PATH value and don't parse it.
Can you catch the exception in debug build?
rjmholt commentedon Mar 5, 2020
The second part is Linux, but my point is about exec.
If exec is failing there will be no exception; it's a native API.
I could be wrong about the provenance of the issue though. We need to see the whole error message (if you could add that please George (@gdoenlen))
gdoenlen commentedon Mar 5, 2020
Rob Holt (@rjmholt) The part after export will change depending on what it encounters in the path first.
gdoenlen commentedon Mar 5, 2020
Does powershell leave a log anywhere? I could check that as well.
rjmholt commentedon Mar 5, 2020
I think it can be configured to, but I don't think at the level we're looking for; it's designed to log commands rather than its internals. But all of this happens so early anyway that we avoid all possible work to reduce startup time (since we have to start up twice).
iSazonov commentedon Mar 5, 2020
So we see bash error for
export. I guess it is possible to repo without PowerShell.gdoenlen commentedon Mar 5, 2020
Just for reference I believe /bin/sh points to dash and not bash. My posix shell isn't so great but maybe it's running something from /etc/profile or /etc/profile.d when you use it as a login shell? Though it is odd that bash and zsh as my login shell don't do the same.
rjmholt commentedon Mar 5, 2020
Interesting. We specifically intend to work with dash, but running as login deliberately runs either
/etc/profileor~/.profile. Those are supposed to be/bin/shcompatible according to POSIX13 remaining items
gdoenlen commentedon Mar 16, 2020
Thank you Michael Klement (@mklement0) ! It seems like shellcheck fails to catch this as well.
mklement0 commentedon Mar 16, 2020
Good point, George (@gdoenlen) - a request to add such a check has already been made (by the author of shellcheck himself): koalaman/shellcheck#951
mklement0 commentedon Mar 16, 2020
I've updated the previous comment to paint what I hope is the full picture, but in a nutshell:
/etc/profile.d/apps-bin-path.shscript that ships with Ubuntu.pwshas the user's default shell, given that WSL of necessity always invokes user shells as a login shell to ensure/etc/profileprocessing - unlike in actual Linux (virtual) machines, where that isn't necessary.PATH(e.g. via/etc/enviroment), a blocking error message will pop up during system startup.ExE-Boss commentedon Feb 5, 2021
This has now been fixed in the
snapdGitHub repository: canonical/snapd#9888 (canonical/snapd@ae84b65).gdoenlen commentedon Feb 5, 2021
Any idea when this will make it into WSL? As of today pwsh 7.1.1 is still broken as a login shell.
rkeithhill commentedon Feb 5, 2022
The Engine WG reviewed this issue yesterday. We believe this is an external issue. While
snapdhas applied a fix, that fix was not available on the WSL Ubuntu 20.04 distro we tested. Applying the fix"..."around the RHS manually seems to allow PowerShell to run as a login shell: