POSIX defines a text file as "a file that contains characters organized into zero or more lines". However, according to POSIX definition of a line, there are two possible "kinds" of text files with zero lines:
- an empty file
- a non-empty file consisting solely of a single incomplete line (a line with at least one character and no
\n).
Is the second case above really considered a text file? Intuitively it's not, as it seems to be nothing more but an edge case. Still, such a file certainly has no lines (as POSIX defines them) because it does not contain a newline character, so it seems to adhere to the current POSIX definition of a text file. The only issue open to interpretation here may be whether such files can be considered "organized into lines", but personally I see no reason against it - nothing in the POSIX definition forces me to treat them otherwise than empty files which, despite being empty (and thus trivially having zero lines), are considered "organized in lines". Perhaps I'm splitting hairs here, but I think the definition, as it currently stands, requires a slight augmentation in order to exclude this case (unless I'm wrong and such files are indeed supposed to match the POSIX definition of a text file).
In this thread:
What conditions must be met for a file to be a text file as defined by POSIX?
the OP had similar doubts. In one of replies to his questions someone claimed that "a text file shall not have incomplete lines". While this extra statement would indeed exclude the disputed case, such a restriction does not explicitly appear in the POSIX definition of a text file.
foois a valid text file since it contains zero lines, why not also assume thatfoo\nbaris a valid text file since it contains more than zero lines?\n, it can't be a text file). I'll be eqally blunt as ilkkachu there: this is all pretty straightforward, and you electing to have a problem with it is a bit of a "Peter" thing :) and doesn't…