Line endings, also known as newline characters, signify the end of a line of text. They might seem insignificant, but they play a crucial role in ensuring our files are accurately interpreted and processed.
One of the biggest places where this impacts us is when talking about cross-platform compatibility. Different operating systems interpret line endings differently. A file created on Windows might not display correctly on Unix systems without the proper line ending conversion.
This is because on Windows we use Carriage Return + Line Feed (CRLF
or \r\n
) whereas on Unix/Linux/MacOS: Line Feed (LF
or \n
) is used.
I got into trouble with line endings when trying to run a docker image. Instead of running the image as expected, I got a “file not found” error for a specific file.
After some investigation, I found out that the root cause was indeed the used line ending. After changing it and rebuilding the docker image I was finally able to run it successfully.
In VS Code, you can see the line ending used in the status bar at the bottom:
Change the line ending through VS Code
To change the line ending, you can click on the current line ending in the status bar and choose a different line ending
Don’t forget to save the changed file afterwards.