Skip to content

Parameter values disambiguated with their explicit parameter names should not require quoting #4576

@mklement0

Description

@mklement0

In order to pass a parameter value that looks like a parameter name you currently have to use quoting - sometimes.

However, if you explicitly precede the value with its parameter name as opposed to passing it positionally, no quoting should be necessary.

Especially with respect to PowerShell's CLI and all its quoting headaches, this extra quoting requirement should be reconsidered - see #4351

Steps to reproduce

'hi'>'-t.txt'; Get-Content '-t.txt'; Get-Content -LiteralPath -t.txt

Expected behavior

hi
hi

The two Get-Content commands should be equivalent:

  • In the 1st case, the quoting implies that -t.txt is a parameter value rather than a name.
  • In the 2nd case, the explicit use of parameter -LiteralPath, which requires a value, should unambiguously identify the next token as the parameter value - even if it starts with - - whether quoted or not.

Actual behavior

hi
Get-Content : Parameter cannot be processed because the parameter name 't' is ambiguous. Possible matches include: -TotalCount -Tail.
...

That is, despite being preceded by -LiteralPath, which requires a parameter value,
unquoted -t.txt was not interpreted as that parameter's value, but as another parameter name.

Environment data

PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions