Thomas (boggyb) wrote,

  • Mood:
  • Music:

Metasyntatic directories

Today's random discovery is that, on Linux, carriage returns are valid characters in directory names.

How did I find this out? Because Bash is stupid and doesn't understand that a carriage return is a line delimiter. Instead it thinks the character is a literal character (like a letter or number), and so turns mkdir /foo/barCRLF into mkdir /foo/barCR. This creates a directory named "bar" followed by a carriage return. Which of course appears as merely "foo" in a web page, leading to all sorts of fun questions as to why a listing of /foo claims "bar" exists when listing /foo/bar returns an error.

But surely we can get around this with quoting? Surely mkdir "/foo/bar"CRLF will work?

Nope! See, Bash tries to be clever, and moves the CR inside the quote marks. Seriously. It then runs mkdir "/foo/barCR".

I eventually resorted to putting a comment at the end of every line to get this to work (and no, the obvious fix of using Linux line endings was not possible because this script was being entered in a web page, and line endings in web page forms are always normalised to CRLF). Sigh.

A bit of background for non-techies: computers these days generally use one of two sets of control characters to end a line of text. Windows uses a carriage-return/line-feed pair (CRLF), while Linux uses just a line-feed (LF). Most of the time this isn't an issue as any text editor smarter than Notepad understands either style.
Tags: computing, rant

  • How not to get people to use a new feature

    What I want to do: use my laptop. What I actually end up doing: go digging through the settings to find out why I have a new "Meet Now" icon in the…

  • Of carpentry and networking

    So, I'm not sure if I've bought a wifi router or a Cylon Raider here... Work colleague: Cylon raider. So say we all. Housegroup friend: Or a…

  • Foam filter 1, case fan 0

    Did you know that a foam dust filter is capable of milling away the leading edges of a PC case fan? That particular fan was mounted to the top…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.