sh read on files missing the final newline
Edgar Fuß <[email protected]> Mon, 6 Jul 2026 18:27:01 +0200
| Newsgroups | gmane.os.netbsd.devel.userlevel |
|---|---|
| Message-ID | <akvXVSX/[email protected]> |
I stumbled over the fact that sh's read returned 1 on the final part (call it a line or not) of a file when it didn't end in a newline. Digging through SUS revealed (in the informative part of read): Although the standard input is required to be a text file, and therefore will always end with a <newline> (unless it is an empty file) as well as other passages that suggested that a "text file" consists of "lines" and a "line" is a sequence of non-newline characters plus a newline, but I couldn't find a definition explicitly stating that.