Wednesday, February 28, 2018
Notes on an overheard conversation while driving south along I-95
“When are they going to finish all this contruction? The road here is terrible!”
“It keeps the drivers on their toes.”
“The lanes are all uneven! It could force you into the next lane!”
“Yes, that's what makes it exciting.”
A potential way to have spaces in filenames and not break the Unix command line
A thread at
Hacker News about using makefiles for JavasScript
was about the
difficulty in using filenames with spaces.
And yes, it is difficult.
A Makefile
such as:
hello world:
Results in:
[spc]lucy:/tmp/foo>make make: Nothing to be done for `hello'. [spc]lucy:/tmp/foo>
Enclosing the filename with quotes (single or double, it doesn't matter) gives the same results. If I escape the space like:
hello\ world:
make
gives:
[spc]lucy:/tmp/foo>make cc hello world.c -o hello world cc: hello: No such file or directory cc: world.c: No such file or directory cc: world: No such file or directory cc: no input files make: *** [hello world] Error 1 [spc]lucy:/tmp/foo>
So yes,
using a filename with spaces is problematic with make
.
Part of that is the unique nature of the space character.
In ASCII,
it's grouped next to the information separator characters and thus,
could be treated as another type of separator character
(and on input, it usually is considered such).
It could also be considered a control character as a format effector such that it causes the character position to advance one place to the right
(and is thus used as such with output).
It's the prevasive use of space as a separator in Unix that causes the most issues,
such with make
,
and the command line in general.
But there is a solution …
[spc]lucy:/tmp/foo>ll total 12 -rw-r–r– 1 spc spc 14 Feb 28 18:13 Makefile -rw-r–r– 1 spc spc 76 Feb 28 18:13 hello world.c -rw-r–r– 1 spc spc 227 Feb 28 18:13 x.lua [spc]lucy:/tmp/foo>cat Makefile hello world: [spc]lucy:/tmp/foo>make cc hello world.c -o hello world [spc]lucy:/tmp/foo>./hello world Hello, world! [spc]lucy:/tmp/foo>
No, the output is not faked.
Yes,
the filename is hello world.c
.
The name,
however,
is not pure ASCII—it contains the Unicode character for a “non-breaking space”.
Cheating?
Perhaps.
But it is defined as a space (graphically),
and more importantly,
it's not considered an information separator by Unix utilties.
It also requires a filesystem that can support Unicode (or in my case, UTF-8)
and a command line that also supports Unicode (or again in my case, UTF-8).
And it was also not that easy to create the filename and Makefile
with the non-breaking space.
But other than those minor issues [Ha! —Editor], hey—spaces! In filenames!