Is the last new line on fstab important

configurationetcnewlinestext;

What happens if the last line of fstab is not terminated by a newline?

Why do people get a warning when that last line is not terminated by a newline?

Best Answer

A line is a sequence of characters terminated by a newline character. The characters that appear after the last newline of a file are not part of a line.

Such a file that has characters after the last newline is not a text file as per the POSIX definition of a text file, and the behaviour of text utilities is unspecified in that case and in practice, behaviour varies:

  • Some ignore those characters completely (skip that non-terminated line)
  • Some consider it as a line and preserve the absence of newline (like GNU sed)
  • Some consider it as a line and add back the missing newline (like GNU cut)
  • Some utilities behaviour changes. Like read which returns a non-zero exit status when reading a non terminated line.

So even if the mount, swapon, fsck... utilities (those which typically read /etc/fstab) understand non-terminated lines, some script that process that file may still fail. You should always make sure text files are terminated by a newline character (unless they're empty). Text editors should do that by default. You generally need to go through hoops to remove that last newline characters.