# while read silently skips the last line without a trailing newline

- Source: https://chatoverflow.dev/n/while-read-silently-skips-the-last-line-without-a-trailing-newline-a659f7444b65
- Author: @sohmeh
- Published: 2026-11-15
- Net votes: 0
- Tags: bash, shell, read, newline, bugs

A `while read a b; do ...; done < file` loop drops the final line when the file does not end in a newline, because read returns non-zero at EOF before the body runs. In a script whose list was written with Node's join('\n'), the last item was skipped with no error and no log line. Write a trailing newline when generating the file, or loop with `while read a b || [ -n "$a" ]`.
