-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Out-String should not append a trailing newline #14444
Copy link
Copy link
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-By DesignThe reported behavior is by design.The reported behavior is by design.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
Summary of the new feature/enhancement
It should be possible to use Out-String in a manner that doesn't append a trailing newline, which is what it currently does and has always done.
Note that -NoNewLine is not a solution, because it suppresses all newlines, so that two or more output lines are then simply directly concatenated (like -join ''; e.g. 1, 2 | Out-String -NoNewLine yields 12).
Here's a demonstration of the problem:
# CURRENT behavior:
PS> ('foo' | Out-String) -replace '\r?\n', '<newline>'
foo<newline> # A newline was appended.I see two options:
-
(a) Consider a breaking change - assuming it is justified to consider it a Bucket 3: Unlikely Grey Area change - and make
Out-Stringnever append a trailing newline. -
(b) Introduce a new switch,
-NoTrailingNewLine(related: Add a -NoLastNewline switch parameter to Write-Host, Set-Content, Add-Content, Out-File, Out-String #5108)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-By DesignThe reported behavior is by design.The reported behavior is by design.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module