You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mcroce@t490s:~$ pwshPowerShell 7.2.0Copyright (c) Microsoft Corporation.https://aka.ms/powershellType 'help' to get help.PS /home/mcroce>mcroce@t490s:~$
Actual behavior
mcroce@t490s:~$ pwshPowerShell 7.2.0Copyright (c) Microsoft Corporation.https://aka.ms/powershellType 'help' to get help.PS /home/mcroce> mcroce@t490s:~$
Error details
No response
Environment data
Name Value
---------
PSVersion 7.2.0
PSEdition Core
GitCommitId 7.2.0
OS Linux 5.15.0 PowerShell/PowerShell#47 SMP Tue Nov 2 23:55:47 CET 2021
Platform Unix
PSCompatibleVersions {1.0,2.0,3.0,4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
to output an empty line firest (there is no need for a space between the quotes, you can put any text 'exiting' or a an empty string, or even $null there.)
Because PSReadline is responsible for handling (and changing or acting on) commands as typed but before they are submitted it won't insert a new line, and if you type EXIT [enter] you already have a new line. Exit is immediate exit and if it suffixed lines to output that would change the results of existing code which uses exit, so it would be a breaking change.
As explained elsewhere #16256 ctrl-D isn't a shortcut key but the end of file marker; different OSes use different characters (ctrl Z gets you out of windows' nslookup, but ctrl D gets you out of the unix/linux version) and not all shells see input as a continuous file stream.
I never argued about ctrl-D. Ctrl-D isn't any shortcut, it's just a way to let the shell send an EOF to the process stdin.
The problem here is that no new line is print after an EOF.
The same issue exists when the shell reads an EOF, it's not related to ctrl-d at all.
mcroce@t490s:~$ echo date |bash
mer 8 dic 2021, 18:05:41, CET
mcroce@t490s:~$ echo date |dash
mer 8 dic 2021, 18:05:44, CET
mcroce@t490s:~$ echo date |zsh
mer 8 dic 2021, 18:05:47, CET
mcroce@t490s:~$ echo date |pwsh
PowerShell 7.2.0
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /home/mcroce> date
mer 8 dic 2021, 18:05:50, CET
PS /home/mcroce> mcroce@t490s:~$
Above you can see that every shell writes a new line when reaching the end of the stdin, but powershell doesn't and clobbers the prompt.
No ctrl-d involved at all this time, just regular end of stream reached.
I'm not sure if the issue is actually printing the prompt when there is no more input.
You're right at best the behaviour is untidy. I thought this and the referenced query were basically the same thing, my bad on that.
Well, other shells don't print the prompt if there is an EOF.
I think that this could be solved either by printing a new line, or by suppressing the last prompt.
I looked at the code, the latter is a bit more difficult.
The ctrl+d behavior in PowerShell Emacs and Vi modes is achieved by 2 functions bound to ctrl+d. They are DeleteCharOrExit and ViAcceptLineOrExit. So, the best solution would be to update those functions to write a new line before ending the process.
Key Function Description
--- -------- -----------
Ctrl+d DeleteCharOrExit Delete the character under the cursor, or if the line is empty, exit the process.
Key Function Description
--- -------- -----------
Ctrl+d ViAcceptLineOrExit If the line is empty, exit, otherwise accept the line as input.
<Ctrl+d> ViAcceptLineOrExit If the line is empty, exit, otherwise accept the line as input.
Activity
jhoneill commentedon Nov 15, 2021
if you are using
you can make it
to output an empty line firest (there is no need for a space between the quotes, you can put any text 'exiting' or a an empty string, or even $null there.)
Because PSReadline is responsible for handling (and changing or acting on) commands as typed but before they are submitted it won't insert a new line, and if you type
EXIT [enter]you already have a new line.Exitis immediate exit and if it suffixed lines to output that would change the results of existing code which uses exit, so it would be a breaking change.As explained elsewhere #16256 ctrl-D isn't a shortcut key but the end of file marker; different OSes use different characters (ctrl Z gets you out of windows' nslookup, but ctrl D gets you out of the unix/linux version) and not all shells see input as a continuous file stream.
teknoraver commentedon Dec 8, 2021
Hi,
I never argued about ctrl-D. Ctrl-D isn't any shortcut, it's just a way to let the shell send an EOF to the process stdin.
The problem here is that no new line is print after an EOF.
The same issue exists when the shell reads an EOF, it's not related to ctrl-d at all.
Above you can see that every shell writes a new line when reaching the end of the stdin, but powershell doesn't and clobbers the prompt.
No ctrl-d involved at all this time, just regular end of stream reached.
jhoneill commentedon Dec 8, 2021
I'm not sure if the issue is actually printing the prompt when there is no more input.
You're right at best the behaviour is untidy. I thought this and the referenced query were basically the same thing, my bad on that.
teknoraver commentedon Dec 8, 2021
Well, other shells don't print the prompt if there is an EOF.
I think that this could be solved either by printing a new line, or by suppressing the last prompt.
I looked at the code, the latter is a bit more difficult.
teknoraver commentedon Aug 17, 2022
I just retried with a fresh build, and now ^D doesn't even terminates the shell.
This is the strace log:
What has been changed?
microsoft-github-policy-service commentedon Nov 15, 2023
microsoft-github-policy-service commentedon Nov 22, 2023
microsoft-github-policy-service commentedon Feb 18, 2026
daxian-dbw commentedon Feb 18, 2026
The
ctrl+dbehavior in PowerShellEmacsandVimodes is achieved by 2 functions bound to ctrl+d. They areDeleteCharOrExitandViAcceptLineOrExit. So, the best solution would be to update those functions to write a new line before ending the process.sdwheeler commentedon Feb 18, 2026
See related PR - PowerShell/PowerShell#16439 (comment)