Title: PowerShell incorrectly tokenizes `-i.bk` when invoking external commands on Linux · Issue #26452 · PowerShell/PowerShell · GitHub
Open Graph Title: PowerShell incorrectly tokenizes `-i.bk` when invoking external commands on Linux · Issue #26452 · PowerShell/PowerShell
X Title: PowerShell incorrectly tokenizes `-i.bk` when invoking external commands on Linux · Issue #26452 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/26452
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PowerShell incorrectly tokenizes `-i.bk` when invoking external commands on Linux","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nWhen 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.\nThis causes `sed` to misinterpret the options and fail with an error such as:\n\n```console\n> sed -i.bk 's/foo/bar/' file.txt\n/usr/bin/sed: -e expression #1, char 1: unknown command: `.'\n```\n\n### Root Cause Hypothesis\nPowerShell'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.\n\n\n### Expected behavior\n\n```console\nPowerShell should pass `-i.bk` as a single argument to the external command, preserving the intended behavior of `sed`.\n```\n\n### Actual behavior\n\n```console\nPowerShell splits `-i.bk` into two tokens: `-i` and `.bk`, resulting in incorrect execution.\n\n\n# This fails in PowerShell on Linux\nsed -i.bk 's/foo/bar/' file.txt\n\n# This works correctly in bash or other shells\nbash -c \"sed -i.bk 's/foo/bar/' file.txt\"\n\n\n### Result of `Trace-Command`\n\n> Trace-Command -Name CommandDiscovery,ParameterBinding -Expression { sed -i.bk 's/foo/bar/' test.txt } -PSHost\nDEBUG: 2025-11-15 01:29:56.1475 CommandDiscovery Information: 0 : Looking up command: sed\nDEBUG: 2025-11-15 01:29:56.1478 CommandDiscovery Information: 0 : PATH: ... \nDEBUG: 2025-11-15 01:29:56.1479 CommandDiscovery Information: 0 : Looking for sed in ...\n(snip)\nDEBUG: 2025-11-15 01:29:56.1672 CommandDiscovery Information: 0 : Command Found: path (/usr/bin/sed) is an application with name: sed\nDEBUG: 2025-11-15 01:29:56.1674 ParameterBinding Information: 0 : BIND NAMED native application line args [/usr/bin/sed]\nDEBUG: 2025-11-15 01:29:56.1675 ParameterBinding Information: 0 : BIND cmd line arg [-i] to position [0]\nDEBUG: 2025-11-15 01:29:56.1675 ParameterBinding Information: 0 : BIND cmd line arg [.bk] to position [1]\nDEBUG: 2025-11-15 01:29:56.1676 ParameterBinding Information: 0 : BIND cmd line arg [s/foo/bar/] to position [2]\nDEBUG: 2025-11-15 01:29:56.1676 ParameterBinding Information: 0 : BIND cmd line arg [test.txt] to position [3]\nDEBUG: 2025-11-15 01:29:56.1682 ParameterBinding Information: 0 : CALLING BeginProcessing\n/usr/bin/sed: -e expression #1, char 1: unknown command: `.'\n```\n\n### Error details\n\n```console\n\n```\n\n### Environment data\n\n```powershell\nName Value\n---- -----\nPSVersion 7.6.0-preview.5\nPSEdition Core\nGitCommitId 7.6.0-preview.5\nOS Ubuntu 24.04.3 LTS\nPlatform Unix\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\nPSRemotingProtocolVersion 2.4\nSerializationVersion 1.1.0.1\nWSManStackVersion 3.0\n```\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/teramako","@type":"Person","name":"teramako"},"datePublished":"2025-11-14T16:47:39Z","url":"https://github.com/PowerShell/PowerShell/issues/26452"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:274c90a4-5d38-3623-e1d0-c2f5a9d7f58c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C432:1007B2:1888D1:229729:6AFD5023 |
| html-safe-nonce | 48eba0ec65ef9a8de4cd3511d9c1d8e5246efbf7f3f3a3475342f2d2cbab974e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDMyOjEwMDdCMjoxODg4RDE6MjI5NzI5OjZBRkQ1MDIzIiwidmlzaXRvcl9pZCI6IjE0OTk5MDI0ODY3OTI0NTgyNzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d576248b355d0b7d0873a921ab437943062514f192454e36ecde7c2e3ec4f071 |
| hovercard-subject-tag | issue:3626386605 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/26452/issue_layout |
| twitter:image | https://opengraph.githubassets.com/372b9ba7997c173657632ad98114bdbc067b2d44c3ba49243ed0f65d78282f3b/PowerShell/PowerShell/issues/26452 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/372b9ba7997c173657632ad98114bdbc067b2d44c3ba49243ed0f65d78282f3b/PowerShell/PowerShell/issues/26452 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | teramako |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width