On 10/6/22 12:59 PM, Andrea Monaco wrote:
The readline manual says that: "If readline encounters an EOF while
reading the line, and the line is empty at that point, then (char *)NULL
is returned. Otherwise, the line is ended just as if a newline had been
typed" (from lib/readline/doc/rltech.texi).
But the second sentence appears wrong. When I type Ctrl-D at a readline
prompt and the line is non-empty, nothing happens. You can check at any
readline prompt, including bash.
It's confusing. The ^D character is the stty EOF character, and is a valid
bindable readline key sequence. It's not the same as encountering EOF,
which is indicated by read(2) returning 0.
When readline reads ^D on an empty line, it returns NULL. If it reads
^D and the line isn't empty, it deletes the character following the cursor.
So on an empty line, readline simulates an EOF by returning NULL.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/