Skip to content

Native tilde expansion is inappropriately applied indirectly, to arguments supplied via unquoted variable references #27192

Open

Description

Prerequisites

Steps to reproduce

Native tilde when calling external (native) programs is inappropriately also applied to indirectly passed unquoted arguments, via variable values.

This is not how tilde expansion works in POSIX-compatible shells, which PowerShell is meant to emulate.

Note: By contrast, with respect to pathname expansion (globbing), an indirectly passed argument should and does still expand, as long as the variable reference is passed unquoted (e.g. printf $var). This discrepancy is owed to the order in which POSIX-compatible shells perform shell expansions.

While the workaround is to quote a reference to a variable whose value starts with ~ (e.g. printf "$var"), this shouldn't be necessary.

# On Unix; applies analogously to Windows in v7.6.0+
# Show Bash' behavior.
bash -c "arg1='~'; printf '%s\n' `$arg1"
# Putatively equivalent PowerShell behavior.
$arg1 = '~'; printf '%s\n' $arg1

Expected behavior

~
~

That is, the argument should be passed verbatim in both cases.

Actual behavior

~
/home/jdoe

That is, PowerShell still expanded ~, even though it was provided via a variable value.

Error details

Environment data

PowerShell 7.6.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Apr 5, 2026
  2. mklement0 commented on Apr 6, 2026

    @mklement0
    ContributorAuthor

    Yes, the by-design advent of tilde expansion in Windows in 7.6.0 undoubtedly technically constitutes a breaking change.

    The presumption must have been that this is acceptable, due to being unlikely to affect real-world scripts, i.e. that the breaking change falls into bucket 3.

  3. added
    WG-NeedsReview
    WG-Engine
    on Apr 6, 2026
  4. mklement0 commented on Oct 10, 2026

    @mklement0
    ContributorAuthor

    I just realized that this came up before, before the formerly PSNativeWindowsTildeExpansion experimental feature became a stable one; the linked issue provides additional background:

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-TriageWG-EngineWG-NeedsReview

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions