Skip to content

PSNativeWindowsTildeExpansion breaks commands like wsl bash ~/run-task.sh, add option for disabling #28183

Open

Description

Prerequisites

Steps to reproduce

~ is being inappropriately expanded in commands where it is not supposed to be expanded. See example. In general, I would like ~ to never be expanded, so I would like an option to disable this "feature".

Expected behavior

PS> wsl bash ~/run-task.sh
< Output of run-task.sh >

Actual behavior

PS> wsl bash ~/run-task.sh
bash: C:UsersArnav/run-task.sh: No such file or directory

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.6
PSEdition                      Core
GitCommitId                    7.6.6
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. mklement0 commented on Oct 10, 2026

    @mklement0
    Contributor

    Duplicate of the following, which was closed as by-design:

    Quote paths to avoid the problem; wsl bash '~/run-task.sh' in your case.

  2. arnavbhate commented on Oct 10, 2026

    @arnavbhate
    Author

    Not entirely duplicate, clarified title

  3. changed the title [-]PSNativeWindowsTildeExpansion breaks commands like `wsl bash ~/run-task.sh`[/-] [+]PSNativeWindowsTildeExpansion breaks commands like `wsl bash ~/run-task.sh`, add option for disabling[/+] on Oct 10, 2026
  4. mklement0 commented on Oct 11, 2026

    @mklement0
    Contributor

    To clarify:

    • Your issue was submitted as a bug report, and as such it is a duplicate of Regression: wsl ~ works in 7.5 but fails in 7.6 due to tilde expansion and argument mangling #27098

    • It sounds like it should have been submitted as a feature request; because it wasn't, it lacks the Issue-Enhancement label (which I personally cannot add).

    • As for the nature of your feature request:

      • It sounds like you're looking to have the option to deactivate a formerly experimental feature, PSNativeWindowsTildeExpansion, which became a stable, unconditional one in v7.6, and you presumably want that option to be implemented in the form of a yet to be introduced new preference variable (if not, please clarify).

      • As noted, ad hoc you can simply use quoting to deactivate the feature.

  5. arnavbhate commented on Oct 11, 2026

    @arnavbhate
    Author

    Not a duplicate because wsl ~ shouldn't work, but it used to. But this should work, and it doesn't. The option is a method I am suggesting to resolve the bug, but not the only one.

  6. mklement0 commented on Oct 11, 2026

    @mklement0
    Contributor

    wsl ~ shouldn't work, but it used to. But this should work, and it doesn't.

    The form wsl ~ is incidental to the problem at hand; the root cause is the same as with your command form, wsl bash ~/run-task.sh, or any other form involving unquoted, argument-initial ~ (either ~ in isolation or if followed by / or, on Windows, alternatively \):

    • The intentional behavioral change to make PowerShell itself expand unquoted, argument-initial ~ to the path of the current user's home (profile) directory up-front, on Windows too, introduced in v7.6, whereas up to v7.5 ~ was passed through as-is to the target program.

    As such, there is no bug, only an intentional change, as implied by the resolution of #27098 - notwithstanding the fact that it is possible that it wasn't anticipated that the change amounted to a breaking one in the context of Unix-like CLIs on Windows, notably wsh.exe and bash.exe, which need to do their own interpretation of ~, differing from PowerShell's.


    • If your argument is that the new behavior is a bug nonetheless, I suggest you elaborate, especially with a view to demonstrating real-world impact.

      • Should the team agree with your assessment, the only way to fix the problem without removing the new feature altogether would be to introduce a "blacklist" of Unix-like CLIs to which the new feature should not apply.
      • Such an approach is obviously fraught (it's impossible to anticipate all relevant CLIs, both currently and going forward). That said - for better or worse - it has been done before, in the form of a whitelist in the context of the $PSNativeCommandArgumentPassing preference variable
    • Asking for a configuration option (e.g. via a preference variable) to revert to the old behavior is at odds with considering the new behavior a bug, however; as noted, it amounts to a feature request.

      • Here too it would help your case if you elaborated on the exact implementation of the desired configuration option.
      • That said, my personal sense is that this unlikely to be implemented, given the narrow use case, the potential to affect other code, and the fact that an ad hoc solution is very simple (quoting, as discussed).

    The more specific your request / arguments are, the more likely they are to be reviewed by the relevant working group.
    (Note that as of this writing the issue isn't even tagged as needing working-group review.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions