- Notifications
You must be signed in to change notification settings - Fork8.1k
Open
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on thelatest released version
- Search the existing issues.
- Refer to theFAQ.
- Refer toDifferences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
When running thesed command with the-i.bk option (to specify a backup suffix), PowerShell on Linux fails to execute the command correctly. It appears that PowerShell's command-line parser splits the-i.bk argument into multiple tokens, treating.bk as a separate argument.
This causessed to misinterpret the options and fail with an error such as:
>sed -i.bk's/foo/bar/' file.txt/usr/bin/sed: -e expression #1, char 1: unknown command: `.'
Root Cause Hypothesis
PowerShell's command-line parser may be incorrectly splitting arguments that begin with a dash (-) and contain a dot (.), assuming the dot introduces a separate token. This behavior is inconsistent with standard shell parsing and breaks compatibility with many Unix-style tools.
Expected behavior
PowerShell should pass `-i.bk` as a single argument to the external command, preserving the intended behavior of `sed`.Actual behavior
PowerShell splits `-i.bk` into two tokens: `-i` and `.bk`, resulting in incorrect execution.#This failsin PowerShell on Linuxsed -i.bk 's/foo/bar/' file.txt#This works correctlyin bash or other shellsbash -c "sed -i.bk 's/foo/bar/' file.txt"### Result of `Trace-Command`>Trace-Command -Name CommandDiscovery,ParameterBinding -Expression { sed -i.bk's/foo/bar/' test.txt } -PSHostDEBUG: 2025-11-15 01:29:56.1475 CommandDiscovery Information: 0 : Looking up command: sedDEBUG: 2025-11-15 01:29:56.1478 CommandDiscovery Information: 0 : PATH: ...DEBUG: 2025-11-15 01:29:56.1479 CommandDiscovery Information: 0 : Looking for sed in ...(snip)DEBUG: 2025-11-15 01:29:56.1672 CommandDiscovery Information: 0 : Command Found: path (/usr/bin/sed) is an application with name: sedDEBUG: 2025-11-15 01:29:56.1674 ParameterBinding Information: 0 : BIND NAMED native application line args [/usr/bin/sed]DEBUG: 2025-11-15 01:29:56.1675 ParameterBinding Information: 0 : BIND cmd line arg [-i] to position [0]DEBUG: 2025-11-15 01:29:56.1675 ParameterBinding Information: 0 : BIND cmd line arg [.bk] to position [1]DEBUG: 2025-11-15 01:29:56.1676 ParameterBinding Information: 0 : BIND cmd line arg [s/foo/bar/] to position [2]DEBUG: 2025-11-15 01:29:56.1676 ParameterBinding Information: 0 : BIND cmd line arg [test.txt] to position [3]DEBUG: 2025-11-15 01:29:56.1682 ParameterBinding Information: 0 : CALLING BeginProcessing/usr/bin/sed: -e expression #1, char 1: unknown command: `.'
Error details
Environment data
Name Value---------PSVersion7.6.0-preview.5PSEdition CoreGitCommitId7.6.0-preview.5OS Ubuntu24.04.3 LTSPlatform UnixPSCompatibleVersions {1.0,2.0,3.0,4.0…}PSRemotingProtocolVersion2.4SerializationVersion1.1.0.1WSManStackVersion3.0
Visuals
No response