Interview Prep/Shell Scripting/Troubleshooting: quoting, expansion and tool-input bugs

A `while read` loop silently skips the last line of a config file.

BeginnerTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer

Likely causes → The file does not end with a newline. read returns non-zero at EOF even though it read data into the variable, so the loop body is skipped for the final line.

Diagnose → tail -c1 file | od -c shows no \n at the end.

Fix →

while IFS= read -r line || [[ -n $line ]]; do
  ...
done < file

Prevent → Configure editors to add a final newline; use the || [[ -n $line ]] idiom in every read loop.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: quoting, expansion and tool-input bugs