friendica.eskimo.com

Is Ctrl+D really like Enter?

Response to a recent claim that Ctrl+D in the terminal is like pressing Enter. It kind of is but it’s also misleading to say so without further explanation.


Linux Terminal: CTRL+D is like pressing ENTER


Honestly I had no idea what ctrl+d even did, I just knew it was a convenient way for me to close all the REPL programs I use. The fact that it is similar to pressing enter really surprised me, so I wanted to share this knowledge with you :)


https://hackarcana.com/article/ctrl-d-is-like-enter

This entry was edited (3 days ago)
31 3
Isn't ctrl-m the "enter" equivalent?
Yes. So is Ctrl+J actually. Ctrl+J corresponds to line feed (LF) and Ctrl+M corresponds to carriage return (CR) ASCII characters. They are typically treated the same way.
8

Found it in the classic The UNIX Programming Environment from 1984:

But then, this is for return, which technically isn't "enter", but nowadays they are sort of interpreted the same by programs?

This entry was edited (3 days ago)
8 1
Yeah, it’s a bit philosophical.
* In graphical applications, Ctrl+M, Ctrl+J and Return/Enter are all different things.
* In a terminal in raw mode, Ctrl+M and Return/Enter are the same thing but Ctrl+J is something different. You can for example run bind -x '"\C-j":"echo a"' in bash and Ctrl+J will do something different.
* In a terminal in canonical mode, they are all the same thing. There probably are some stty options which can change that though.
This entry was edited (3 days ago)
2
I don't get the reference. This is the first time I've read that claim. But I'd certainly hope people know there is a difference between End Of Line and End Of File... I mean they're alike, they both end something. But it's not the same thing. The article explains the details how it's handled.
This entry was edited (3 days ago)
7

Yeah, my bad. I should have linked to the previous post: discuss.tchncs.de/post/3263718… (not entirely sure what’s the etiquette for linking to posts on Lemmy is).


Linux Terminal: CTRL+D is like pressing ENTER


Honestly I had no idea what ctrl+d even did, I just knew it was a convenient way for me to close all the REPL programs I use. The fact that it is similar to pressing enter really surprised me, so I wanted to share this knowledge with you :)


https://hackarcana.com/article/ctrl-d-is-like-enter

2
Right, I must have scrolled past it. I think linking posts is fine. I mean they're public and this is social media... At least I do it somewhat regularly and I've never had anyone complain.
I meant what’s the link to use since the same Lemmy post can be viewed through different instances and on each it has a different URL. It’s a bit user-hostile that the link gets you out of your instance (unless you’re on the same instance as author of the post).
1
That's right. I don't think there is a good way to do it. I just take whatever link is provided by the small Fediverse icon. But I don't think it matters that much for your audience, they're spread over several instances and it'll be an external link for some of them, no matter what you do. I'm not sure whether we have the ambition to solve this. I don't see anything the user could do. Either this gets handled in some way by the software, or it is how it is.
This entry was edited (3 days ago)
I often exit a shell with ctrl+d. And I often see if a shell is still connected by pressing enter. They are definitely not equivalent.
51

👆

Let's say it together: No, it isn't

This entry was edited (3 days ago)
23 1
Control-D gives a hex value of 0x04, where as ENTER or CR gives a hex value of 0x0d,
they are not the same. Control D returns the carriage on old tty machines, on many modern linux platforms it is treated as CRLF, that is carriage return and a linefeed. Control-D indicates end of file or end of transmission.