-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Unix utilities expect $env:PWD to reflect the current directory, as per POSIX #7388
Comments
Is there a goal to make PowerShell POSIX compliant? |
It's not about POSIX compliance per se - it's just that POSIX-decreed functionality is, by and large, the common denominator across macOS and Linux - see #6518 (comment) If PowerShell wants to be a good cross-platform citizen and aspires to be the "universal shell" (which I hope it does), it must not contravene fundamental expectations of any platform's native utilities. Utilities (command-line programs) on Unix-like platforms may rely on environment variable PowerShell not respecting that can lead to subtle failures. If you want a specific example: After switching my default shell to PowerShell on macOS, my (standardized across projects) |
I believe it will be easy-to-fix and good enhancement. |
Set the UNIX Environment variable $env:PWD to the full filesystem path for the current working directory upon Set-Location. This also copes when the current location is set to a PSDrive. In such circumstances the environment variable is expanded to the full FileSystem provider path. Fixes PowerShell#7388 Signed-off-by: Daniel Llewellyn <daniel@bowlhat.net>
Set the UNIX Environment variable $env:PWD to the full filesystem path for the current working directory upon Set-Location. This also copes when the current location is set to a PSDrive. In such circumstances the environment variable is expanded to the full FileSystem provider path. Fixes PowerShell#7388 Signed-off-by: Daniel Llewellyn <daniel@bowlhat.net>
Just got bitten by this after changing my login shell to pwsh My particular issue can be solved by setting
|
Code references: PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs Lines 2133 to 2165 in 356355c
PowerShell/src/System.Management.Automation/engine/NativeCommandProcessor.cs Lines 452 to 453 in 356355c
|
It seems we could implement this with something like this property |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Please re-open this. I believe the benefits far outweigh any cons, if there even are any. For example, I'm using a project with a |
POSIX mandates the presence of an environment variable named
PWD
that should "represent an absolute pathname of the current working directory."That is, POSIX-like shells keep the value of this env. variable in sync with their working dir. so that (non-shell) processes created from the shell can rely on it reflecting the shell's notion of the current dir.
PowerShell currently doesn't set this environment variable (it only sets its internal automatic
$PWD
variable, which other processes cannot see), which can have unintended consequences when invoking Unix utilities that rely on it.This problem is conceptually related to #3428, for which there is no good solution due to its in-process nature.
In the case at hand, however, since a child process must be created to invoke an external program, it should be possible to add a
PWD
environment variable reflecting PowerShell's current filesystem location to the environment block of the new process.Steps to reproduce (on macOS or Linux)
Expected behavior
That is, the external utility's process should see PowerShell's current filesystem location in its
PWD
environment variable.(Note that using another shell (e.g.,
bash
) for this test wouldn't be a valid test, because POSIX-like shells set thePWD
environment variable themselves.)Actual behavior
Even with PowerShell configured as the user's default shell,
$env:PWD
is still set at the time the PowerShell session starts, and seemingly always reflects the user's home dir.Environment data
The text was updated successfully, but these errors were encountered: