CRLF

What now?! Another abbreviation in this gotta type fast with fewest characters possible but still convey the most information possible? Well for us developers the chance is high that you had to search something with those four chars and an Operating System as the search term.

Meaning

The 4 chars are actually two pairs of two chars. The first is CR and the second is LF. CR stands for Carriage Return and LF stands for Line Feed.

Typewriter

Remember those old physical machines where you put whitened wood pulp in and using keys ran into that pulp some iron oxide on a ribbon. Yes, typewriters indeed. Wonderful mechanical machines that made life easier for humans. Now on those machines the sheet of paper would move side to side and up and down. The act of moving back to the beginning is called Carriage Return. The act of moving the sheet of paper is called Line Feeding. See how the terms translate well into modern computers and the terminals they are being run in.

Side note

So on modern Operating Systems there exists a number of terminals or shells. Underwater they are called tty devices, or TeleTypewriter devices. That was because the first type of digital typewriters had a monitor and a typewriter interface. So even more evidence of history and how it all ties together.

CRLF cont.

Ok sorry for the detour but it serves a purpose. Operating Systems interpret those characters differently. On Windows you have to do the same action as on a physical typewriter. Return the carriage to the beginning and feed in a new line. Therefore they use CRLF as the ending. On GNU/Linux and derivatives only feeding a line is necessary. Therefore they have LF only line endings. What does it mean then when you run CRLF file on GNU/Linux and co? Well the shell will do the following. Move the cursor back to the beginning and then execute that line and go to the next but there is no more line endings at the end there remains your command as a garbage input. Garbage in means garbage out. So the scripts usually fail. On Windows the same can happen but the system itself is very good at making sure there never is a singular LF if it can help it.

Docker

What has Docker got to do with this I hear you ask? Ever noticed how most Dockerfile files have got all kinds of RUN commands and not just copy in a shell script and run that? I thought it was much simpler to maintain and read and so I did it. Thinking of how clever I was I suddenly had a team member with Windows and Docker did not work?!?! NANI?!?! After debugging the crap out of it I realized it was CRLF related. Solution is fairly simple though, not use shell scripts unless you copy them in already from a GNU/Linux system or download then from the web. So fellow human software engineers, when using Docker use RUN commands and maybe some staged builds. More on that in a future post/ future posts.

#thoughts #devops