Skip to content

/usr/local/bin/pwsh should be registered as a shell in /etc/shells on mac as it is on linux #6027

Closed

Description

Steps to reproduce

chsh -s /usr/local/bin/pwsh

Expected behavior

pwsh should become your shell

Actual behavior

chsh: /usr/local/bin/pwsh: non-standard shell

bash stays your shell because pwsh is not registered as a shell

Environment data

> $PSVersionTable
Name                           Value                                           
----                           -----                                           
PSVersion                      6.0.0                                           
PSEdition                      Core                                            
GitCommitId                    v6.0.1                                          
OS                             Darwin 17.3.0 Darwin Kernel Version 17.3.0: T...
Platform                       Unix                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1                                         
WSManStackVersion              3.0                                             

Activity

  1. markekraus commented on Jan 25, 2018

    @markekraus
    Contributor

    Michael Klement (@mklement0) Correct me if I'm wrong, but, don't we have to avoid using pwsh as a login shell for various reasons?

  2. TravisEz13 commented on Jan 25, 2018

    @TravisEz13
    MemberAuthor

    I've found at least one on mac... the environment doesn't get loaded properly...

  3. markekraus commented on Jan 25, 2018

    @markekraus
    Contributor
  4. mklement0 commented on Jan 25, 2018

    @mklement0
    Contributor

    Travis Plunk (@TravisEz13):

    If you use sudo chsh -s ..., you'll change the shell for the root user; please use just
    chsh -s /usr/local/bin/pwsh.

    For ad-hoc use, here's an idempotent command for adding pwsh to the list of permissible default shells:

    grep -x /usr/local/bin/pwsh /etc/shells || sudo sh -c 'echo /usr/local/bin/pwsh >> /etc/shells'

    Mark Kraus (@markekraus): I'll address the other issues soon.

  5. mklement0 commented on Jan 25, 2018

    @mklement0
    Contributor

    In general, using pwsh as one's default shell works fine on macOS (I've only tested superficially), except - and that's a big except - for the fact that it doesn't process /etc/profile, where important system-wide initializations happen.

    The previously discussed issue is that /etc/profile cannot be read directly by PowerShell, because it is coded for POSIX-compliant shells (sh; as an aside, note that the language constructs therefore permitted in that file are only a subset of what bash supports).

    On macOS specifically, the only important thing that /etc/profile does (at least by default) is to add important entries to $env:PATH

    Fortunately, that is done via an external utility, /usr/libexec/path_helper, which you can also call from PS; e.g., by placing the following in your $PROFILE file (note the need for extra measures, given that $PROFILE is sourced for every PowerShell instance by default):

      if ($IsMacOS -and $env:PATH -notmatch '\b/usr/local/bin\b') { # prevent repeated replacement of $env:PATH
        & { # Use a child scope, so that helper function setenv() doesn't linger.
          function setenv ($variable, $value) { [Environment]::SetEnvironmentVariable($variable, $value)  }
          # `/usr/libexec/path_helper -c` conveniently outputs something like 'setenv PATH "/usr/local/bin:..."',
          # which we can pass to Invoke-Expression, which then calls our transient `setenv()` function.
          Invoke-Expression (/usr/libexec/path_helper -c)  
        }
      }

    Also, GUI apps on macOS do NOT rely on /etc/profile; the latter's importance seems limited to shells.

    On Linux distros, this **can get trickier **, where the entire system may depend on initializations performed in /etc/profile (I have not delved into this), and where important $env:PATH additions are not conveniently obtainable from a single utility call. Most likely not a problem, after all - see link below.

    Comment #975 (comment) from the (lengthy) linked issue tries to summarize the problem.

  6. TravisEz13 commented on Jan 26, 2018

    @TravisEz13
    MemberAuthor

    I updated the issue with more details on the actual case and removed sudo from the repro as Mark Kraus (@markekraus) suggested.

    I think I agree with Michael Klement (@mklement0) that the shell is mostly usable and I would like to easily be able to switch after I install. Even more so, now that I have the utility that Michael Klement (@mklement0) suggested.

  7. 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.

  8. 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.

  9. 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.

  10. beedell-roke commented on Nov 16, 2023

    @beedell-roke

    #6027 (comment)

    Michael Klement (@mklement0), why is

    grep -x /usr/local/bin/pwsh /etc/shells || sudo sh -c 'echo /usr/local/bin/pwsh >> /etc/shells'

    not a solution? Is the problem withholding this that issues like #6027 (comment) remain?

  11. mklement0 commented on Nov 16, 2023

    @mklement0
    Contributor

    @RokeJulianLockhart: it should work fine.

    The problem of PowerShell's inability to process /etc/profile (and, if present, ~/.profile) itself has been solved by PowerShell re-executing itself via /bin/sh -l behind the scenes, which makes it inherit the the environment from that process.

  12. beedell-roke commented on Nov 16, 2023

    @beedell-roke

    #6027 (comment)

    So I suppose someone just has to make a pull request to implement this then.

  13. mklement0 commented on Nov 16, 2023

    @mklement0
    Contributor

    I agree, at least for installations that use an official installer or package manager, including on Linux.

  14. microsoft-github-policy-service commented on Nov 24, 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-Enhancementthe issue is more of a feature request than a bugOS-macOSResolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions