-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #11038 - Clarify which env vars need to be set outside of PowerShell #11040
Fixes #11038 - Clarify which env vars need to be set outside of PowerShell #11040
Conversation
@@ -359,7 +378,11 @@ The environment variables that store preferences include: | |||
- Use the `Set-ExecutionPolicy` cmdlet. Use the **Scope** parameter with | |||
a value of `Process`. | |||
|
|||
For more information, see [about_Execution_Policies][05]. | |||
- Manually set the environment variable. Changing the value of this variable | |||
changes the execution policy current process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick turnaround; I think "changes the execution policy current process." should be "changes the execution policy for the current process."
on Linux, you can add environment variables to the `/etc/environment` file or | ||
create a script that sets environment variables and put it in the | ||
`/etc/profile.d` folder. On macOS, you can add environment variables to the | ||
`/etc/zshrc` file. For more information, see the documentation for your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that /etc/zshrc
is the appropriate file to use only if zsh
is the user's default shell.
If PowerShell is the default shell, /etc/profile
must be used, because PowerShell, when invoked with -l
(as happens implicitly on macOS for the default shell), reinvokes itself via zsh -l
with the latter in POSIX compatibility mode, where /etc/profile
rather than /etc/zshrc
is sourced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mklement0, can you point to documentation for zsh
that states that. The documentation I found indicated that /etc/zshrc
would be invoked by zsh -l
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdwheeler, when PowerShell re-invokes itself via /bin/zsh -l
, it sets argv[0]
to /bin/sh
, which means that Zsh runs in POSIX compatibility mode, and therefore sources /etc/profile
and ~/.profile
instead. See https://github.com/PowerShell/PowerShell/blob/b968e101b910c9013988685b6b7b33a1451cc1ce/src/powershell/Program.cs#L274-L303
Here's the relevant Zsh docs link: https://zsh-manual.netlify.app/invocation#42-compatibility
This is somewhat unfortunate, as it means that extra effort is needed for users who want to centralize environment-variable definitions while supporting switching the default shell between zsh
and PowerShell. I've updated #10696 (comment) to hopefully now paint the complete picture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As also noted in the linked issue, the /etc/profile
/ /etc/profile.d
approaches on non-GUI Linux distros - e.g. in Docker images - require explicit invocation via pwsh -l
to take effect.
PR Summary
Clarify which env vars need to be set outside of PowerShell
PR Checklist