Ugly file name
Guy Harris
guy at auspex.auspex.com
Fri May 12 18:31:12 AEST 1989
>I once left my brain at home and named a file something like
>'odds&ends' (on a BSD system).
The same situation arises on non-BSD systems.
>I just could not persuade csh to recognize that the '&' was to be
>considered part of the filename -- it just kept putting all of my
>commands trying to refer to the file into the background.
Helpful Hints #1273: if you have a file name containing characters that
the shell assigns special significance to, put the file name in single
quotes when typing it as a file name:
% rm 'odds&ends'
This works for the Bourne shell (any not-hopelessly-busted version),
the C shell (ditto), and the Korn shell (ditto). (Except that for the C
shell this may not work for the "!" character - you have to escape it
with "\". Oh well....)
>and wound up with a file in my home directory with a space in its name!
See previous hint:
% rm 'dir file'
>As I see it (and this is NOT intended as a flame), this illustrates a
>problem with the *nix filesystem: filenames can be created that cannot then
>be sensibly manipulated. I LIKE the flexibility of *nix filenaming where
>you are not required to have a '.' in all filenames (like some OS's which
>shall remain nameless) and (at least with BSD) names can be reasonably long,
>but it can be a hassle when you accidently create a file with a wierd or
>ugly name and then cannot easily rename or delete it.
Yup. However, not all users are necessarily using a "traditional"
command language to get at the system; it's nice that if they want to
stick blanks or "&"s or whatever into their file names, they can do so.
There's a separate problem with characters with the 8th bit set, or
multi-byte characters one or more of whose bytes have the 8th bit set;
some older versions of the shells use that bit internally for quoting,
and strip it off before passing it to the command. One might ask "but
why would you have such a character in a file name"; the answer is "if,
for example, you're keeping some information about Citr\:oen ("\:o"
being "o with a diaresis"), you might want to call name the file after
the car and (former) company in question; the ISO Latin #1 character for
"o with a diaresis" has the 8th bit set".
The S5R3 and later Bourne shell, and the "ksh-i" and later Korn shell,
don't use the 8th bit for quoting, and thus can deal with file names of
that sort (assuming you can type them into your system, which you can
with certain terminals/keyboards and software). The C shell may be able
to do that as well in some future version.
The 4.[23]BSD file system disallows such characters, presumably to
prevent people from creating hard-to-remove files of that sort; however,
it's again a case of "why disallow it, since somebody might legitimately
want to use it", and the SunOS 4.x version of that file system allows
such characters, as will the S5R4 version.
More information about the Comp.unix.wizards
mailing list