New lines at the end of shell scripts

Angel Tsankov fn42551 at fmi.uni-sofia.bg
Sat Jan 31 01:39:09 PST 2009


Robert Russell wrote:
>
> On Thu, Jan 29, 2009 at 4:34 PM, Angel Tsankov
>>
>> Should a shell script end in a new line character ('\n')?
>>
> What do you mean by end in a new line?

I'll explain with an example:

=== file1 ===
echo 'This is line one. It terminates in a line feed character'
echo 'This is line two.  It does not terminate in a line feed character'
== end of file1 ===

=== file 2 ===
echo 'This is line one. It terminates in a line feed character'
echo 'This is line two.  It terminates in line feed character'

== end of file2 ===

I'm asking if it's OK not to end a shell script in a line feed character 
(like file1).  This question is bothering me 'cause when I edit a shell 
script with vi and the last line in the file does not end in a line feed 
character, vi appends one to it.  I wonder what the reason for this might 
be.  In particular, is there any convention or standard that stipulates what 
the last character of a shell script should be or is this just vi's 
behaviour?

--Angel 




More information about the lfs-chat mailing list