[TUHS] non-Posix input files

Douglas McIlroy douglas.mcilroy at dartmouth.edu
Sun Mar 30 22:48:07 AEST 2025


> "The requirement that awk add a trailing <newline> to the program argument
> text is to simplify the grammar, making it match a text file in form."

This should no more be a *requirement* for awk than globbing should have
been a requirement for MS-DOS apps. A widespread principle deserves a
widespread answer. If it is a requirement on awk, then for interoperability
it should be made a requirement on all programs that handle text files,
especially editors.

The way to do that, of course, would be to redefine text file to allow a
non-newline as the last character. Ugh.

Not warning perpetuates travesties like "awk END{print NR}' " giving a different
answer than "wc -l".

I agree that awk does the kind thing by supplying the final newline. But
it should recognize that this is non-standard behavior and warn in the
interest of discouraging the proliferation of garbage.

Postel's so-called "robustness principle" is in play here. "Be conservative
in what you send, be liberal in what you accept" would better read,
"Send conservatively; receive amply but grudgingly".

Doug


More information about the TUHS mailing list