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,082
  • 9
  • 61
  • 111
Devyn Collier Johnson
  • 3,874
  • 2
  • 17
  • 38

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
  • 55
  • 342
  • 375