Skip to content

PowerShell incorrectly tokenizes -i.bk when invoking external commands on Linux #26452

Closed as duplicate

Description

@teramako

Prerequisites

Steps to reproduce

When running the sed 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 causes sed 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 fails in PowerShell on Linux
sed -i.bk 's/foo/bar/' file.txt

# This works correctly in bash or other shells
bash -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 } -PSHost
DEBUG: 2025-11-15 01:29:56.1475 CommandDiscovery Information: 0 : Looking up command: sed
DEBUG: 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: sed
DEBUG: 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
----                           -----
PSVersion                      7.6.0-preview.5
PSEdition                      Core
GitCommitId                    7.6.0-preview.5
OS                             Ubuntu 24.04.3 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Nov 14, 2025
  2. mklement0 commented on Nov 14, 2025

    @mklement0
    Contributor
  3. teramako commented on Nov 14, 2025

    @teramako
    Author

    Yes, this is an unfortunate, long-standing known problem, along with several related ones:

    Thank you for linking to the known issue. 🙇
    I believe it's the exact same problem. I'll patiently wait for it to be fixed .

  4. removed
    Needs-Triage
    on Feb 5, 2026
  5. SeeminglyScience commented on Feb 5, 2026

    @SeeminglyScience
    Contributor

    Thanks for the report! Tracking in the referenced issue

  6. added
    Resolution-Duplicate
    Issue-Bug
    on Feb 5, 2026
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

    Issue-BugResolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions