Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LF Versus CRLF Line Endings in Windows Batch Files

I have a mixed Ubuntu, OS X and Windows git repository containing .bat and .cmd files targeted for use on Windows 7 and greater. core.autocrlf is set to input, and so post-git checkout these files have LF line endings in my working directory instead of the CRLF line-endings I started out with.

Will this cause problems with windows batch execution? In what cases might this difference be significant? I have yet to see any issue but wish to code defensively.

like image 526
Skurhse Avatar asked Aug 08 '16 18:08

Skurhse


People also ask

How can I tell if a file is CRLF or LF?

use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.

Can Windows use LF line endings?

Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character.

What is difference between CRLF and LF?

They're used to note the termination of a line, however, dealt with differently in today's popular Operating Systems. For example: in Windows both a CR and LF are required to note the end of a line, whereas in Linux/UNIX a LF is only required. In the HTTP protocol, the CR-LF sequence is always used to terminate a line.

How do I change the end of line from CRLF to LF?

Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually. You can then use the menu item Edit > EOL Conversion and select Unix (LF). After selection Edit > EOL Conversion > Unix (LF) your file will be correct for submission.


1 Answers

You can override this for batch files using the following .gitattributes file:

*.bat text eol=crlf

From Is it safe to write batch files with Unix line endings? There is a comment about labels not working correctly with LF. The fix is easy enough.

like image 78
Dietrich Epp Avatar answered Sep 27 '22 20:09

Dietrich Epp