Wednesday, February 28, 2018
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.
Makefile such as:
[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:
[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>
using a filename with spaces is problematic with
Part of that is the unique nature of the space character.
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,
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.
the filename is
is not pure ASCII—it contains the Unicode character for a “non-breaking space”.
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!