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
PowerShell should support inheritance of default shell environment variables as a default shell #975
OS X sets up default paths for shells by calling out to path_helper. Bash (and Zsh, and Csh) all execute
eval`/usr/libexec/path_helper -s`
in their respective /etc/profile files. The OS Xy way for PowerShell to do this would be to add a similar call to our system profile.
However, path_helper was of course not designed with PowerShell in mind, and so it only can emit the PATH and MANPATH variables in two styles, C-shell and Bourne shell. We don't really have much of an option but to parse its output and reinterpret it for PowerShell.
changed the title [-]/usr/local/bin should be in a default path[/-][+]/usr/local/bin, /usr/sbin/installer should be in a default path[/+]on May 15, 2016
Looks like more people are hitting this now. My proposed fix for PS7 is to build on #9528 so if -l is used, pwsh will shell out to sh and apply those env vars to itself. umask and other environment factors will not be taken into account pending additional user feedback and addressed case-by-case.
It looks as workaround without RFC defined PowerShell as login shell. Having the RFC Unix distributive maintainers can expose paths in standard way. Ex.: we could have a ps_path_helper utility per Unix distributive and call it at PowerShell login shell startup.
Marc (@cawoodm), are you sure that $NODE_EXTRA_CA_CERTS is defined as an environment variable (typically created with export), and not just as a shell variable? Shell variables aren't seen by child processes.
Try the following (from Bash or any other POSIX-like shell) to verify that a true environment variable is indeed inherited by PowerShell (this syntax creates a command-scoped environment variable):
To me there is no difference: whatever environment variables I have (echo $foo) should be available in child processes like pwsh. PowerShell should not load some other environment - that would break stuff.
Now, we're using WSL and it does not seem to respect /etc/environment so we have added the following to .bashrc:
NODE_EXTRA_CA_CERTS=foo
To be honest I do not know the difference between bar=foo and export bar=foo...
Checking it with bash:
$ echo $NODE_EXTRA_CA_CERTS
foo
Good, checking it with pwsh:
$ pwsh -noprofile -c '$env:NODE_EXTRA_CA_CERTS'
Not Good.
My expectation would be that the current environment is passed to pwsh. I think this is normal behaviour for child processes.
My expectation would be that the current environment is passed to pwsh
Shell(-only) variables are not part of the system-level process environment, which is the only environment child processes inherit. Shell variables are by design limited to the given shell process.
While in cmd.exeall variables are environment variables, both PowerShell and POSIX-like shells such as bash distinguish between shell(-only) variables and environment variables.
While In PowerShell you always use the same, distinct syntax for both creating and querying environment variables ($env:...), in POSIX like shells both types of variables are queried the same, namely with just the $ sigil, as in $NODE_EXTRA_CA_CERTS; that is when you get a variable value, the syntax isn't telling you whether you're accessing a shell(-only) or an environment variable.
In POSIX-like shells, it's the declaration of a variable that matters:
As a stand-alone statement, NODE_EXTRA_CA_CERTS=foo creates a shell(-only) variable - by design, no child process will see it.
What I used above - prepending variable assignments directly to a command invocation (NODE_EXTRA_CA_CERTS=foo pwsh ....) - is syntactic sugar for defining command-scoped environment variables - only the child process created sees them, not the remainder of the script.
If you want to use a stand-alone statement to create an environment variable, use the export utility:
export NODE_EXTRA_CA_CERTS=foo
In POSIX-like shells:
To see all environment variables, run env (in PowerShell you'd use Get-ChildItem env:)
To check whether a given variable is an environment variable, use typeset -p <name> (works in bash, ksh, zsh): if the output contains either -x or export (zsh), the variable is an environment variable (in PowerShell you'd use Get-Item env:<name>).
Activity
andyleejordan commentedon May 14, 2016
OS X sets up default paths for shells by calling out to
path_helper. Bash (and Zsh, and Csh) all executein their respective
/etc/profilefiles. The OS Xy way for PowerShell to do this would be to add a similar call to our system profile.However,
path_helperwas of course not designed with PowerShell in mind, and so it only can emit thePATHandMANPATHvariables in two styles, C-shell and Bourne shell. We don't really have much of an option but to parse its output and reinterpret it for PowerShell.vors commentedon May 14, 2016
It's easy:
string PATH = MANPATH.Replace(':', ';');:)vors commentedon May 15, 2016
Also, it screws up
Start-PSBootstrap(on OS X), because it usesinstaller[-]/usr/local/bin should be in a default path[/-][+]/usr/local/bin, /usr/sbin/installer should be in a default path[/+]vors commentedon May 15, 2016
Meanwhile, here is a one-liner that you can add to the profile to fix it
andyleejordan commentedon May 16, 2016
sergei (@vors) what about
MANPATH?vors commentedon May 19, 2016
Andy Jordan (@andschwa) ah, what's with it?
38 remaining items
SteveL-MSFT commentedon May 6, 2019
Looks like more people are hitting this now. My proposed fix for PS7 is to build on #9528 so if
-lis used, pwsh will shell out toshand apply those env vars to itself.umaskand other environment factors will not be taken into account pending additional user feedback and addressed case-by-case.iSazonov commentedon May 6, 2019
It looks as workaround without RFC defined PowerShell as login shell. Having the RFC Unix distributive maintainers can expose paths in standard way. Ex.: we could have a ps_path_helper utility per Unix distributive and call it at PowerShell login shell startup.
There is a difference between .bash_profile and .profile
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path/226947
I mean that $PATH can be different for login and non-login shells.
SteveL-MSFT commentedon May 6, 2019
Please review https://github.com/PowerShell/PowerShell-RFC/pull/171/files
iSazonov commentedon Jul 11, 2019
Related #10050
cawoodm commentedon Jun 19, 2020
Why does
pwshnot pick up the environment variables frombashwhen it is launched??Crickets...
iSazonov commentedon Jun 19, 2020
Marc (@cawoodm) If you ask about default shell just this was used in #10050.
mklement0 commentedon Jun 19, 2020
Ilya (@iSazonov), Marc (@cawoodm)'s problem is unrelated to this issue.
Marc (@cawoodm), are you sure that
$NODE_EXTRA_CA_CERTSis defined as an environment variable (typically created withexport), and not just as a shell variable? Shell variables aren't seen by child processes.Try the following (from Bash or any other POSIX-like shell) to verify that a true environment variable is indeed inherited by PowerShell (this syntax creates a command-scoped environment variable):
Also note that such inheritance is a system-level feature that exists independently of PowerShell.
If you have a reproducible case where this inheritance indeed doesn't work, please create a new issue.
cawoodm commentedon Jun 19, 2020
To me there is no difference: whatever environment variables I have (echo $foo) should be available in child processes like
pwsh. PowerShell should not load some other environment - that would break stuff.Now, we're using WSL and it does not seem to respect
/etc/environmentso we have added the following to.bashrc:To be honest I do not know the difference between
bar=fooandexport bar=foo...Checking it with bash:
Good, checking it with pwsh:
Not Good.
My expectation would be that the current environment is passed to
pwsh. I think this is normal behaviour for child processes.mklement0 commentedon Jun 19, 2020
Shell(-only) variables are not part of the system-level process environment, which is the only environment child processes inherit. Shell variables are by design limited to the given shell process.
While in
cmd.exeall variables are environment variables, both PowerShell and POSIX-like shells such asbashdistinguish between shell(-only) variables and environment variables.While In PowerShell you always use the same, distinct syntax for both creating and querying environment variables (
$env:...), in POSIX like shells both types of variables are queried the same, namely with just the$sigil, as in$NODE_EXTRA_CA_CERTS; that is when you get a variable value, the syntax isn't telling you whether you're accessing a shell(-only) or an environment variable.In POSIX-like shells, it's the declaration of a variable that matters:
As a stand-alone statement,
NODE_EXTRA_CA_CERTS=foocreates a shell(-only) variable - by design, no child process will see it.What I used above - prepending variable assignments directly to a command invocation (
NODE_EXTRA_CA_CERTS=foo pwsh ....) - is syntactic sugar for defining command-scoped environment variables - only the child process created sees them, not the remainder of the script.If you want to use a stand-alone statement to create an environment variable, use the
exportutility:export NODE_EXTRA_CA_CERTS=fooIn POSIX-like shells:
To see all environment variables, run
env(in PowerShell you'd useGet-ChildItem env:)To check whether a given variable is an environment variable, use
typeset -p <name>(works inbash,ksh,zsh): if the output contains either-xorexport(zsh), the variable is an environment variable (in PowerShell you'd useGet-Item env:<name>).cawoodm commentedon Jun 19, 2020
Thanks Michael Klement (@mklement0) - you da man!