- In Bash, I learned that the ending signal can be changed by here document. But by default how can I signal the end of
- I happened to find that with
stdininputs can be signaled as finished by Ctrl+D. But I seems to remember that Ctrl+D and Ctrl+C are similar to ending execution of a running command. So am I wrong?
Ctrl+D, when typed at the start of a line on a terminal, signifies the end of the input. This is not a signal in the unix sense: when an application is reading from the terminal and the user presses Ctrl+D, the application is notified that the end of the file has been reached (just like if it was reading from a file and had passed the last byte).
Ctrl+C does send a signal, SIGINT. By default SIGINT (the interrupt signal) kills the foreground application, but the application can catch the signal and react in some different way (for example, the shell itself catches the signal and aborts the line you've begun typing, but it doesn't exit, it shows a new prompt and waits for a new command line).
You can change the characters associated with end-of-file and SIGINT with the
stty command, e.g.
stty eof a would make
a the end-of-file character, and
stty intr ^- would disable the SIGINT character. This is rarely useful.
Your second point lumps two completely different things together.
- Ctrl+C sends a kill signal to the running process.
- Ctrl+D sends an End of Transmission character.
You are looking for the latter.
I encountered this while searching for other information. The answers provided are correct but I think too involved with the internal workings.
The simple, non-technical, answer is that Ctrl+D terminates the STDIN file and that Ctrl+C terminates the active application.
Both are handled in the keyboard driver and apply to all programs reading from the keyboard.
To see the difference start a command line shell and enter the
wc command with no arguments. It is now waiting for STDIN input. Type a sentence and "return". Now type Ctrl+D and
wc will complete and give you the line, word and character count.
Do the same thing but type Ctrl+C. wc will terminate with no output.