Christoph Zurnieden: Ctrl-D abfangen/auswerten, aber wie?

Beitrag lesen

Hi,

Bei ^D wird normalerweise SIGTERM von der Shell an das Programm
uebergeben, also so eine Art Shortcut fuer 'kill -15 $PID' u. ae.

Nein, normalerweise leitet das ein EOF in den Stream.

Ja, haette ich doch selber mal probiert, was ich empfohlen habe:
$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
[...]

Haette ich nicht "normalerweise" gesagt, haette ich ja auch noch meine Entschuldigung bringen koennen, das sich das bei mir so eingestellt habe, aber ich musste ja unbedingt voreiligerweise ...

Tja, so geht's ... ;-)

BTW: was sagt eigentlich IEEE Std 1003.1, 2004 Edition (POSIX®)?
(basedefs/xbd_chap11.htm)

11.1.6 Canonical Mode Input Processing

In canonical mode input processing, terminal input is processed in units of lines. A line is delimited by a newline character (NL), an end-of-file character (EOF), or an end-of-line (EOL) character. See Special Characters for more information on EOF and EOL. This means that a read request shall not return until an entire line has been typed or a signal has been received. Also, no matter how many bytes are requested in the read() call, at most one line shall be returned. It is not, however, necessary to read a whole line at once; any number of bytes, even one, may be requested in a read() without losing information.
[...]

Es allerdings nicht so ganz ohne Haekchen:

11.1.9 Special Characters
[...]
EOF

Special character on input, which is recognized if the ICANON flag is set. When received, all the bytes waiting to be read are immediately passed to the process without waiting for a newline, and the EOF is discarded. Thus, if there are no bytes waiting (that is, the EOF occurred at the beginning of a line), a byte count of zero shall be returned from the read(), representing an end-of-file indication. If ICANON is set, the EOF character shall be discarded when processed.
[...]
[XSI] [Option Start] If IEXTEN is set, the ERASE, KILL, and EOF characters can be escaped by a preceding '' character, in which case no special function shall occur. [Option End]

Zudem ist der genau Wert nicht festgelegt, daher vermute ich mal ganz stark, das die Uebrsetzung in Tastendruecke ebenfalls nicht festgelegt ist. Es ist somit "normalerweise" besser ganz zu entfernen.

Aber und auf jeden Fall: es scheint der Teil meiner Steuern, der in die Bildung fliesst ja doch noch Zins zu tragen! ;-)

so short

Christoph Zurnieden