Log in

Metasyntatic directories - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Metasyntatic directories [Tuesday 10th June 2014 at 6:04 pm]

[Tags|, ]
[Feeling |annoyedannoyed]
[Playing |VNV Nation - Saviour [Empires]]

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.
Link | Previous Entry | Share | Next Entry[ 2 pennies | Penny for your thoughts? ]

[User Picture]From: tau_iota_mu_c
Tuesday 17th June 2014 at 10:52 am (UTC)
Er, fix the script?

Html forms as standard take CR/LF. Unix scripts as standard are LF. Standard practice is to munge things back and forth as appropriate.
(Reply) (Thread)
[User Picture]From: boggyb
Sunday 22nd June 2014 at 10:00 pm (UTC)
The web page is part of the Jenkins build server, so not something that I could trivially fix.

Curiously this seems to be browser-dependent - in IE 11 on my machine I could reliably trigger this, but a colleague using Chrome has no problems. I still think Bash could be less stupid regarding line endings, as these days about the only other program with similar issues is Notepad.
(Reply) (Parent) (Thread)