On Sat, Jan 31, at 11:39 Angel Tsankov wrote:
> 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?
>
Vi(m) follows unix conventions and (it) enters a linefeed character
terminator when saves the file (unless you said it otherwise).
This happens by default in dos/windows systems where files don't end up
with a new line character.
If you are in vim and you work on windows systems, and you want to instruct
vim to treat the file format as unix, issue:
:set ff=unix
see more in:
:help 'ff'
> --Angel
Regards,
Ag.
--
http://linuxfromscratch.org/mailman/listinfo/lfs-chat
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page