See bash - How to use while read to read the last line in a file if there’s no newline at the end of the file? - Stack Overflow.