Skip to content

Brackets Treated As Special Characters In Single Quotes #9541

@bigboy-pdb-spam

Description

@bigboy-pdb-spam

Steps to reproduce

In File Explorer on an NTFS volume, create the file: [abc].txt

Following this run:

ls '[abc].txt'

Expected behavior

    Directory: C:\Users\Dave

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2019-05-06 12:07 AM              0 [abc].txt

Actual behavior

No output displayed.

Environment data

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

Additional Cases and Information

The file name can be displayed using tab completion, but the brackets are preceded by back ticks, which indicates that Windows can see the file and assumes that the brackets are special characters. When attempting to list the file using the ls command, the following error is generated:

ls : Cannot find path 'C:\Users\Dave\`[abc`].txt' because it does not exist.
At line:1 char:1
+ ls '.\`[abc`].txt'
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\Dave\`[abc`].txt:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Other commands generate no output or errors as well.

Get-FileHash '[abc].txt'
# Generates no output

1 | Out-File '[abc].txt'
# Generates error stating that the wildcard path did not resolve to a file

According to Microsoft's "About Quoting Rules" page, "When you enclose a string in single-quotation marks (a single-quoted string), the string is passed to the command exactly as you type it. No substitution is performed".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions