Skip to content

CLI: -File-based / shebang-based invocations break with the end-of-parameters token, -- #20208

Open

Description

Prerequisites

Steps to reproduce

--, the (somewhat confusingly named) end-of-parameters token, signals the end of named arguments and treats all remaining token as positional arguments.

This mechanism is broken when calling via pwsh -File, which also happens implicitly when you call a shebang line-based PowerShells script (that doesn't have a .ps1 extension).

The -- is mistakenly interpreted as a parameter without a name.

# On Unix:
# Create a simple shebang-based script.
@'
#!/usr/bin/env pwsh
[CmdletBinding()]
param(
  $a,
  [Parameter(ValueFromRemainingArguments)] $rest
)
"`$a: $a"
"`$rest: $rest"
'@ > tmpscript
chmod a+x tmpscript

# Invoke as stand-alone executable via the shebang line
./tmpscript -a one -- -a other stuff

# Invoke explicitly via pwsh -File
pwsh -File ./tmpscript -a one -- -a other stuff

Expected behavior

$a: one
$rest: -a other stuff

That is, only one should bind to -a, with all arguments following -- binding to -rest, and the -- itself should be removed.

Actual behavior

Both calls fail with:

: Parameter cannot be processed because the parameter name '' is ambiguous. [...]

That is, -- was misinterpreted as a reference to a parameter without a name.

If you were to rename tmpscript to tmpscript.ps1 and invoke it in-process, the behavior would be as expected.

Error details

No response

Environment data

PowerShell 7.4.0-preview.5 on Unix-like platforms.

Visuals

No response

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-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions