wryun / es-shell

es: a shell with higher-order functions
http://wryun.github.io/es-shell/
Other
313 stars 26 forks source link

`incomplete here document` kills the shell #100

Closed jpco closed 1 month ago

jpco commented 7 months ago
; cat << EOF
abc
^D
stdin:4: incomplete here document

and the shell dies.

(http://wryun.github.io/es-shell/mail-archive/msg00733.html)

jpco commented 1 month ago

The problem here is similar to #111, actually. fdfill(), which is what's fetching input for snarfheredocs(), reads 0 characters at some point due to the ^D, so it dutifully closes down the input (close(in->fd) and the next few lines). Then the expected stuff happens -- a syntax error exception is thrown, the repl retries, and on the next read the shell sees the input has been closed down so an eof exception gets thrown and the shell exits.

So what's desirable seems to be to prevent shutting down the input while reading a heredoc. Will have to be careful to make sure this correctly handles both the "don't kill the interactive session" and "don't hang after falling off the end of a script" cases.