You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
/usr/local/bin/pwsh should be registered as a shell in /etc/shells on mac as it is on linux #6027
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
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.functionsetenv ($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.
Reacted by Ilya and Mr Beedell, Roke Julian Lockhart
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.
Reacted by Michael Klement and Mr Beedell, Roke Julian Lockhart
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.
Reacted by Mr Beedell, Roke Julian Lockhart
microsoft-github-policy-service commented on Nov 16, 2023
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.
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.
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.
Activity
markekraus commentedon Jan 25, 2018
Michael Klement (@mklement0) Correct me if I'm wrong, but, don't we have to avoid using
pwshas a login shell for various reasons?TravisEz13 commentedon Jan 25, 2018
I've found at least one on mac... the environment doesn't get loaded properly...
markekraus commentedon Jan 25, 2018
#975
mklement0 commentedon Jan 25, 2018
Travis Plunk (@TravisEz13):
If you use
sudo chsh -s ..., you'll change the shell for the root user; please use justchsh -s /usr/local/bin/pwsh.For ad-hoc use, here's an idempotent command for adding
pwshto the list of permissible default shells:Mark Kraus (@markekraus): I'll address the other issues soon.
mklement0 commentedon Jan 25, 2018
In general, using
pwshas 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/profilecannot 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 whatbashsupports).On macOS specifically, the only important thing that
/etc/profiledoes (at least by default) is to add important entries to$env:PATHFortunately, 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$PROFILEfile (note the need for extra measures, given that$PROFILEis sourced for every PowerShell instance by default):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 inMost likely not a problem, after all - see link below./etc/profile(I have not delved into this), and where important$env:PATHadditions are not conveniently obtainable from a single utility call.Comment #975 (comment) from the (lengthy) linked issue tries to summarize the problem.
TravisEz13 commentedon Jan 26, 2018
I updated the issue with more details on the actual case and removed
sudofrom 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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
beedell-roke commentedon Nov 16, 2023
Michael Klement (@mklement0), why is
not a solution? Is the problem withholding this that issues like #6027 (comment) remain?
mklement0 commentedon Nov 16, 2023
@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 -lbehind the scenes, which makes it inherit the the environment from that process.beedell-roke commentedon Nov 16, 2023
So I suppose someone just has to make a pull request to implement this then.
mklement0 commentedon Nov 16, 2023
I agree, at least for installations that use an official installer or package manager, including on Linux.
microsoft-github-policy-service commentedon Nov 24, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.