-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add a -NoLastNewline switch parameter to Write-Host, Set-Content, Add-Content, Out-File, Out-String #5108
Description
Follow-up to #3684.
With multiple input objects, the -NoNewline switch causes said cmdlets to not only omit a trailing (last) newline, but also not to place newlines between the (output representations of) the input objects on output.
However, perhaps more typically, you want to only suppress a trailing newline, so it would be handy to have a -NoLastNewline parameter (mutually exclusive with -NoNewLine) that does just that.
If #3855 gets implemented, an alias -NoLastDelimiter could be defined, which would effectively turn the application of the delimiter from terminator logic (place delimiter after every item, including the last) into separator logic (place delimiter only between items).
Desired behavior
Out-Stringexample:
PS> 'a', 'b' | Out-String -NoLastNewline
a
bNote that without -NoLastNewLine you'd get a blank line at the end, due to an extraneous newline getting appended, as discussed in #14444 (which asked for -NoLastNewLine to become the default behavior, but that was declined due to backward-compatibility concerns).
Write-Hostexample:
PS> 'a', 'b' | Write-Host -NoLastNewline; Write-Host 'c'
a
bcNote that with -NoNewline you'd get abc.
Input object-internal (embedded) newlines should be left untouched by both -NoLastNewline and
-NoNewline (though the latter doesn't do so consistently at present - see #5107).
Environment data
PowerShell Core v6.0.0-beta.8