Skip to content

Error when trying to use powershell 7.1 as default shell of ubuntu 20.04 in wsl #14055

Closed

Description

Steps to reproduce

Install powershell 7.1 in wsl ubuntu 20.04, then run the following command:

chsh -s /usr/bin/pwsh

Restart wsl, and an error will occur.

Expected behavior

Start powershell in wsl ubuntu 20.04 normally.

Actual behavior

An error occured:

: 6: export: (x86)/Dev-Cpp/TDM-GCC-64/bin:/mnt/c/Program: bad variable name

(Maybe pwsh will load all Windows PATH before running wsl, C:\Program Files (x86)\Dev-Cpp\TDM-GCC-64\bin is the first in my PATH)

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Linux 4.4.0-19041-Microsoft #488-Microsoft Mon Sep 01 13:43:00 PST 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Nov 12, 2020
  2. fMichaleczek commented on Nov 12, 2020

    @fMichaleczek
    Contributor

    Hyperhydrochloric Acid (@HCl-10) I had problems with WSL and PATH which contains "Program Files" to compile OpenWrt, so I am sure it's a PowerShell Issue. see microsoft/WSL#1640 (comment)

  3. anmenaga commented on Nov 12, 2020

    @anmenaga

    Dongbo Wang (@daxian-dbw) may have more info on this.

  4. iSazonov commented on Nov 13, 2020

    @iSazonov
    Collaborator
  5. added
    Issue-Bug
    WG-Engine
    and removed
    Issue-Question
    on Nov 13, 2020
  6. jonstelly commented on Aug 16, 2021

    @jonstelly

    Any ideas on this one? I have the same issue. I've got Ubuntu 20.04 WSL and the apt package install of powershell 7.1.X gives me the following error when configured as my shell: : 6: export: (x86)/Microsoft: bad variable name.

    Oddly, if I install the dotnet global tool: sudo dotnet tool update --tool-path /usr/local/bin powershell and use that location as my shell I do not get this error.

    I'd prefer to use the APT install, especially since the nuget tool package is a few days late with the 7.1.4 update and it would just feel more natural to use the APT install.

  7. TBBle commented on Aug 20, 2021

    @TBBle

    As noted in #14640, the problem is probably that something is trying to

    export PATH=...
    

    and the ... is not quoted correctly for the current shell, so the first thing that has a space before it, and doesn't look like a valid shell env-var name, i.e. (x86)/Microsoft or (x86)/Dev-Cpp/TDM-GCC-64/bin:/mnt/c/Program, causes this error.

    I would guess that PowerShell is being asked to evaluate a bash script, and differences in quoting behaviour (not a bug) are breaking this. So not really a PowerShell issue, unless reading the script is a built-in PowerShell behaviour.

    I think it's much more likely it's a WSL issue, that (per microsoft/WSL#1640 (comment)) WSL's appendWindowsPath feature is assuming bash is the shell when it appends that path, and hence the quoting is incorrect when PowerShell is the shell.

  8. jonstelly commented on Aug 20, 2021

    @jonstelly

    Any suggestions of how I might debug this? The error message isn’t super helpful.

    Also, why the dotnet global tool install works but the apt package doesn’t? I’m guessing some configuration that comes with the apt package but not with the global tool?

  9. TBBle commented on Aug 20, 2021

    @TBBle

    Assuming disabling appendWindowsPath avoids the issue (at the cost of not having Windows's $PATH in the WSL $PATH), then the problem is probably in the appendWindowsPath implementation, which might have magic to detect PowerShell, but it is failing for the APT-installed version.

    It's also possible that the reason it works with the global tool version is that the global tool version has known issues in command-line parsing and quotes, e.g. #11747, and those issues coincide with the appendWindowsPath implementation to work (or at least not-fail).

    One other thing to check: Does appendWindowsPath actually work with the gobal tool install? You've mentioned that it doesn't give the error, but I don't know if that means that appendWindowsPath is successful, or if it's just failing in a way that doesn't produce an error.

  10. jonstelly commented on Dec 16, 2021

    @jonstelly

    This seems to be caused by an issue in Ubuntu in /etc/profile.d/apps-bin-path.sh. It sounds like apps-bin-path.sh has been fixed in 21.10 but Ubuntu on WSL is still 20.04.

    Work-around: #9842 (comment)

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  14. added
    Resolution-No Activity
    on Nov 16, 2023
  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugOS-WSLResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions