File Termination

In accordance with the POSIX standard, the last line of a file should be empty - that is, the file should have a new-line character appended to the last line.

Why? The POSIX standard is intended to provide compatibility with many command line tools, such as `cat`.

If you use cat on a file that does not have th final new-line character and you haven’t configured your shell to allow for that, you may find your prompt appearing on the same line as the last line of the output of cat.

file1
1File1Line12File1Line2
$ cat file1 file2
File1Line1
File1Line2$

If you use cat on two files and the first one does not have the final new-line character, the first line of the second file will be appended to the last line of the first file.

file2
1File2Line12File2Line23  
$ cat file1 file2
File1Line1
File1Line2File2Line1
File2Line2
$

Swapping the order of the files so the file with the final new-line character is first will output each line on it’s own, but your prompt may still end up on the same line as the last line of the output.

$ cat file2 file1
File2Line1
File2Line2
File1Line1
File1Line2$ 
IDE Configuration

This can be achieved auto-magically by configuring your IDE.

For VS Code the settings are:

settings.json
1{
2    "editor.renderFinalNewline": "off",
3    "files.insertFinalNewline": true,
4}