Skip to content

"-"-prefixed barewords in argument mode should always be interpreted as parameter names #4591

@mklement0

Description

@mklement0

#4578 shows that you can sometimes use --prefixed bareword as parameter values - namely only if the bareword happens not to (prefix)-match a parameter name of the target command - and when such barewords are recognized as values, they don't behave the same way as non---prefixed barewords with respect to interpolation and being recognized as a single argument.

This inconsistency is problematic.

Given, @lzybkr's comment at #4576 (comment)

The "workaround" is in my opinion the preferred style - use quotes.

it seems that the desired solution is to disallow --prefixed barewords as values and to always assume that such an unquoted --prefixed token is a parameter name.

# Currently interpreted as *value*, because no Write-Output parameter name starts with -z.
# This should no longer be supported.
> Write-Output -InputObject -z
-z

# Interpreted as *parameter name*, because -n prefix-matches parameter -NoEnumeration
> Write-Output -InputObject -n
Write-Output : Missing an argument for parameter 'InputObject'. Specify a parameter of type 'System.Management.Automation.PSObject[]' and try again.

Environment data

PowerShell Core v6.0.0-beta.5

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 reclassifResolution-AnsweredThe question is answered.WG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions