Skip to content

Windows: tilde expansion when calling native programs cannot be suppressed with backtick escaping #27112

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

v7.6 promoted the experimental PSNativeWindowsTildeExpansion feature to a stable one, which now causes unquoted ~(-prefixed) arguments passed to native (external) programs to be expanded up front to the value of $HOME, i.e. the current user's full home directory path on Windows too - a feature that has been in place on Unix-like systems for some time now.

However, unlike on Unix, escaping ~ as `~ in order to suppress the expansion does not work on Windows.

choice /d Y /t 0 /m '~'
choice /d Y /t 0 /m "~"
choice /d Y /t 0 /m `~

Expected behavior

~ [Y,N]?Y
~ [Y,N]?Y
~ [Y,N]?Y

Note: the [Y,N]?Y suffix is incidental and an artifact of using choice.exe as a sample native program capable of echoing its input.

Actual behavior

~ [Y,N]?Y
~ [Y,N]?Y
C:\Users\jdoe [Y,N]?Y

That is, `~ unexpectedly did not prevent the expansion.

Error details

Environment data

PowerShell Core v7.6.0 (.NET 10.0.5) on Microsoft Windows 11 Pro (ARM 64-bit Processor; Version 25H2, OS Build: 26200.8037)

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions