1

Why is it recommended that shell scripts end in a new line? I noticed that many programmers leave an empty line at the end of their scripts. Is there a specific reason or POSIX recommendation?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Devyn Collier Johnson
  • 4,124
  • 3
  • 18
  • 39

1 Answers1

4

In many cases a line is defined as ending with a Newline, so you could say that by leaving it out your last "line" is not a line.

Works as expected

$ printf 'foo\n' > bar.txt

$ while read; do echo $REPLY; done < bar.txt
foo

No output here

$ printf 'foo' > qux.txt

$ while read; do echo $REPLY; done < qux.txt
Zombo
  • 1
  • 62
  • 391
  • 407