Skip to content
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

Merged

Conversation

sdwheeler
Copy link
Contributor

@sdwheeler sdwheeler commented Apr 22, 2024

PR Summary

Clarify which env vars need to be set outside of PowerShell

PR Checklist

  • Descriptive Title: This PR's title is a synopsis of the changes it proposes.
  • Summary: This PR's summary describes the scope and intent of the change.
  • Contributor's Guide: I have read the contributors guide.
  • Style: This PR adheres to the style guide.

Copy link
Contributor

Learn Build status updates of commit 90011ab:

✅ Validation status: passed

File Status Preview URL Details
reference/5.1/Microsoft.PowerShell.Core/About/about_Environment_Variables.md ✅Succeeded View (powershell-5.1)
reference/7.2/Microsoft.PowerShell.Core/About/about_Environment_Variables.md ✅Succeeded View (powershell-7.2)
reference/7.2/Microsoft.PowerShell.Core/About/about_Telemetry.md ✅Succeeded View (powershell-7.2)
reference/7.3/Microsoft.PowerShell.Core/About/about_Environment_Variables.md ✅Succeeded View (powershell-7.3)
reference/7.3/Microsoft.PowerShell.Core/About/about_Telemetry.md ✅Succeeded View (powershell-7.3)
reference/7.4/Microsoft.PowerShell.Core/About/about_Environment_Variables.md ✅Succeeded View (powershell-7.4)
reference/7.4/Microsoft.PowerShell.Core/About/about_Telemetry.md ✅Succeeded View (powershell-7.4)
reference/7.5/Microsoft.PowerShell.Core/About/about_Environment_Variables.md ✅Succeeded View (powershell-7.5)
reference/7.5/Microsoft.PowerShell.Core/About/about_Telemetry.md ✅Succeeded View (powershell-7.5)

For more details, please refer to the build report.

For any questions, please:

@michaeltlombardi michaeltlombardi merged commit 87058ca into MicrosoftDocs:main Apr 22, 2024
6 checks passed
@sdwheeler sdwheeler deleted the sdw-w247899-i11038-i11039 branch April 22, 2024 18:19
@@ -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.
Copy link
Contributor

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
Copy link
Contributor

@mklement0 mklement0 Apr 22, 2024

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants