Hacker News new | ask | show | jobs
by bityard 637 days ago
I don't know if your comment was intended to imply that Docker was against the Unix philosophy in some way (a debatable point, but not really one I share), or if you mean that the tools don't follow a lot of common Unix convension.

When Docker was only a few years old, I did keep running into lots of small things which implied that the people developing docker in fact did NOT have a Unix (or even Linux) background. Things like source code files having the wrong type of newlines (or a mix of types), and forgetting to add a newline to the last line in a file. (A correct Unix text file has a newline at the end of _every_ line, even the last one.) There were of course more giveaways than this, I just remember the newline stuff irritating me the most.

1 comments

Why is newline at the end relevant?

I remember not having a newline breaks some tools... but why? It can't be because of unix philosophy!?

Unix's first job in life was as a documentation processing system. It was made to be very good at dealing with text. All of the tools which process text expect every line to end in a newline. The last line is not exempt from this. All classic Unix text editors will automatically append a trailing newline to any text file you create with them. Some modern tools may be _tolerant_ of omitted trailing newlines, but you shouldn't rely on that. A text file should always have a newline as its last character. Otherwise, it's not _really_ a text file.

POSIX defines it more succinctly than I do: A text file contains one or more "lines" and every "line" is terminated by a "newline."

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...

Some old tools had bugs where they'd read a line (up to the new line) and then process it, so if the last line didn't end with a new line they'd never do the processing. So a manual workaround for bugs became the convention.
Back in ~2002 this was the case with cron. Found out the hard way when all the backup tapes we desperately needed were completely empty.
No, that is not a bug and there was never such a thing as "manually" adding a trailing newline. All tools add newlines automatically where they should be.

Unix has ALWAYS defined a line of text as being terminated by a newline. The last line in the file is not an exception.

so that you can cat(1) multiple files at once, and their bookends don't get glued.