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?
Asked
Active
Viewed 362 times
1
-
I've read before that it makes them slightly easier to parse, same reason gcc wants/used to want a newline at the end of the file. – macduff Jun 25 '13 at 22:21
-
That makes sense. make that comment an answer and I will mark it as the answer. – Devyn Collier Johnson Jun 25 '13 at 22:22
-
1super asked question previously. See http://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-file – bbill Jun 25 '13 at 22:23
-
1I did not find that page awhile ago. I marked my question as a duplicate. – Devyn Collier Johnson Jun 25 '13 at 22:23
-
1Yeah, good question though. – bbill Jun 25 '13 at 22:24
1 Answers
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