Repository navigation
Parameter parsing/passing: an unquoted argument that starts with a "-" (hyphen) is broken in two at the first "." (period) #6291
Description
Note that . should receive no special treatment in tokens such as -foo=bar.baz, because the token is unquoted and does not start with a special char. ($ @ ( ' " ) and should therefore result in interpretation as an (expandable) string, according to about_Parsing.
In reality, though, the unexpected special treatment stems from - being the 1st character, which causes interpretation as a parameter name, even though that doesn't apply in this case.
Steps to reproduce
# Helper function that echoes all arguments.
function Out-Argument { $i = 0; $Args | % { 'arg[{0}]: {1}' -f $i++, $_ } }
# Pass an unquoted argument that starts with "-" and has an embedded "." (outside of "..." or '...')
Out-Argument -foo=bar.bazExpected behavior
arg[0]: -foo=bar.baz
Actual behavior
arg[0]: -foo=bar
arg[1]: .baz
The token was unexpectedly broken in two. Note that this equally applies when calling external utilities.
And it is indeed in the context of calling external programs that an argument with such (non-PowerShell) syntax (-<param-name>=<value>) may need to be passed - see this SO question and this one.
(PSv2 exhibited a variation of the bug - see this SO question.)
Environment data
PowerShell Core v6.0.1 on macOS 10.13.3
PowerShell Core v6.0.1 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.1 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)Workarounds
# "`"-escape the leading "-"
Out-Argument `-foo=bar.baz
# Quote the whole argument
Out-Argument '-foo=bar.baz'
Activity
SteveL-MSFT commentedon Dec 10, 2020
Garrett hit this trying to use cmake with pwsh: https://twitter.com/fearthecowboy/status/1336758436583809026
mklement0 commentedon Dec 10, 2020
Just to clarify, Steve Lee (@SteveL-MSFT): it isn't that a space is inserted - that's just how it manifests in a test command such as
cmd /c echo -foo=bar.none; what happens is that the part of the argument starting with the (first).is passed as a separate argument.#14364 should be closed as a duplicate.
Work around PowerShell/PowerShell#6291
SteveL-MSFT commentedon Dec 16, 2020
@PowerShell/powershell-committee reviewed this, we believe the treatment of the period as an argument separator is a bug that should be fixed. A bucket 3 breaking change.
mklement0 commentedon Dec 16, 2020
Glad to hear it, Steve Lee (@SteveL-MSFT).
I hope that fixing this will also address #6292 and #6360.
_content/doc: fix go mod edit for PowerShell
ceztko commentedon Oct 6, 2021
Is this still on track for 7.2?
14 remaining items
nathankrueger commentedon Feb 8, 2024
I can't use Powershell for my project because of this.
robbycbennett commentedon Feb 16, 2024
Here's a real example for usage of the period in arguments. File names usually have periods.
The command was taken from https://clang.llvm.org/docs/StandardCPlusPlusModules.html.
robbycbennett commentedon Feb 16, 2024
This has been an issue for a long time. I see it on version 5 and on version 7.
robbycbennett commentedon Feb 17, 2024
I can see five characters that are allowed in Unix shell unquoted strings that aren't allowed in PowerShell:
{},.[In the file
src/System.Management.Automation/engine/parser/tokenizer.cs, if I removecase '.':from line 3211, then this problem is fixed. However, it probably breaks some other functionality.Before change:
After change:
rkeithhill commentedon Aug 25, 2025
WG-Engine looked at this today and agree it is worth pursuing a bug fix for native commands. Attempting to fix this for commands in general, would be too risky. This area of the code is tricky because the native command parser only gets the tokens that made up the command line, but we believe the original argument can be recreated from these tokens.
Fix hyphen-prefixed arguments being split at period
Fix hyphen-prefixed arguments being split at period
-i.bkwhen invoking external commands on Linux #26452 as a duplicate of this issueFix Azure VM Windows test flags splitting on dotted build IDs (#774)