Skip to content

Regression: wsl ~ works in 7.5 but fails in 7.6 due to tilde expansion and argument mangling #27098

Closed

Description

@smzmster

Prerequisites

Steps to reproduce

Summary

wsl ~ works in PowerShell 7.5 but fails in PowerShell 7.6 due to unexpected tilde expansion and argument mangling

Steps to reproduc

Run the following command in PowerShell:
wsl ~

the command fails with:

/bin/bash: line 1:
 D:Users<username>: command not found

Additional information

The issue does not occur in cmd.exe
The issue did not occur in PowerShell 7.5
This suggests a regression or change in native argument passing behavior in 7.6

Workarounds

The following commands work as expected:
wsl --cd ~
wsl "~"

Expected behavior

~ should be passed to WSL and resolved to the Linux home directory (e.g. /home/<user>).
This is the behavior observed in PowerShell 7.5.

Actual behavior

In PowerShell 7.6, the command fails with:

/bin/bash: line 1:
 D:Users<username>: command not found

It appears that:
1. ~ is expanded by PowerShell into a Windows path (e.g. D:\Users\<username>)
2. The backslashes (\) are stripped or mangled when passed to the native command
3. The resulting string (D:Users<username>) is interpreted by bash as a command

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.0
PSEdition                      Core
GitCommitId                    7.6.0
OS                             Microsoft Windows 10.0.26200
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. added
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Mar 26, 2026
  2. mklement0 commented on Mar 26, 2026

    @mklement0
    Contributor

    Per https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features, the v7.5.x experimental PSNativeWindowsTildeExpansion feature was promoted to a stable feature in v7.6.

    That is, by design, an unquoted ~ (either stand-alone or if followed by \ or /) now expands to the value of $HOME on Windows too (using Windows-native directory-path separators, i.e. \), which explains the behavior you're seeing.

    Thus, use wsl '~' to pass ~ verbatim to wsl.exe

    As an inconsequential aside: it is unclear why the specific command wsl ~ even worked to begin with, given that ~ is interpreted as a shell command and executing a directory path as such doesn't normally work; for instance, wsl /tmp fails (and even if it worked, it wouldn't enter an interactive session).

    By contrast, using the --cd option works robustly, even with tilde expansion; that is, wsl --cd ~ also works in v7.6, but sets the Windows home directory as the working directory (whereas wsl --cd '~' does what you want).

    Lists the currently available experimental features and how to use them.
  3. rhubarb-geek-nz commented on Mar 27, 2026

    @rhubarb-geek-nz

    If you start from a basic cmd.exe session and run

    wsl ~
    

    It launches an interactive session. Effectively the tilde has no effect.

    However if you use

    wsl -- ~
    

    Which passes all following arguments to the shell, then you get

    /bin/bash: line 1: /home/bythesea: Is a directory
    

    So wsl itself does not expand the tilde, it is only when it gets passed into bash that it then expands it.

  4. mklement0 commented on Mar 27, 2026

    @mklement0
    Contributor

    rhubarb-geek-nz: As noted, it is curious that wsl '~' works at all, because operands (non-option) arguments are interpreted as the components of a shell command by default - even without explicit --; try wsl '~/foo', for instance, and you'll see that the ~ gets expanded.
    In other words: it seems that with everything (that doesn't look like an option) other than a stand-alone ~ as the sole argument, wsl ... behaves the same as wsl -- ...; normally, wsl '~' should fail with /bin/bash: line 1: /home/jdoe: Is a directory, but inexplicably doesn't.

    That said, this is an incidental aspect - a quirk of wsl.exe; the root cause of the problem at hand is the by-design decision to bring tilde expansion in the context of calling external programs to Windows too (a feature that isn't WSL-specific)

  5. mklement0 commented on Mar 27, 2026

    @mklement0
    Contributor

    Dongbo Wang (@daxian-dbw), I don't think the interactive WG is the right one for review, given that the feature in question isn't specific to interactive use (it is distinct from how ~ tab-completes).

    In fact, I think Resolution-By Design is the right label, given that the change in behavior is the result of a previously experimental feature becoming a stable one.

  6. daxian-dbw commented on Mar 27, 2026

    @daxian-dbw
    Member

    I tagged WG-Engine instead. I want the WG to review this issue to measure the impact. It's regression after all.

  7. mklement0 commented on Mar 28, 2026

    @mklement0
    Contributor

    Understood, Dongbo Wang (@daxian-dbw). (Strictly speaking, it isn't a regression, though - tilde expansion was never an official feature; it was briefly part of a larger experimental feature that got scrapped).

    What makes the wsl.exe case tricky (applies equally to the deprecated bash.exe) is that ~ refers to a different home directory than on the Windows side.

  8. rkeithhill commented on Apr 12, 2026

    @rkeithhill
    Collaborator

    Yet another workaround: wsl --% ~

  9. SeeminglyScience commented on Apr 20, 2026

    @SeeminglyScience
    Contributor

    The Engine WG discussed this, as described by Michael Klement (@mklement0) above, this is by design.

  10. added
    WG-ReviewedA Working Group has reviewed this and made a recommendation
    and removed
    WG-NeedsReviewNeeds a review by the labeled Working Group
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Apr 20, 2026
  11. microsoft-github-policy-service commented on Apr 22, 2026

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as by-design and has not had any activity for 1 day. It has been closed for housekeeping purposes.

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

Metadata

Metadata

Labels

Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions