[Table of Contents]


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ARSCLIST] Underscore in file names



On Wed, Sep 06, 2006 at 06:48:51AM -0400, Tom Fine wrote:

> So this brings up a question, since I switched out of MacOS years ago
> -- now that MacOS sits on top of FreeBSD, or something along those
> lines, do the filenames with spaces that I'm sure the vast majority of
> Mac users prefer get translated in the underlying file tables or can
> FreeBSD just handle the spaces?

As far as I know, most reasonably current Unix filesystems, including
HFS+ can handle spaces in the file names as it is just another Unicode
or ASCII character code.  The issue is that the shell will interpret a
space on the command line as a file separator if you don't enclose the
file name in quotes or "escape" the spaces with backslashes ('\'). Take
for example, the file name "My Demo CD - Take 1.aiff".  If you use the
command 'ecaplay' (a CLI audio player for Unix) to play the file like
this:

  $ ecaplay My Demo CD - Take 1.aiff

The filename will be interpreted as distinct files separated by the
spaces:

    My
    Demo
    CD
    -
    Take
    1.aiff

Obviously, this won't work.  However any of the following will work:

  $ ecaplay 'My Demo CD - Take 1.aiff'
  $ ecaplay "My Demo CD - Take 1.aiff"
  $ ecaplay My\ Demo\ CD\ -\ Take 1.aiff

The real problems come in when you're passing lots of filenames as
variables in a shell script and have to ensure that your variables
expand to strings that have spaces and other strange characters enclosed
in quotes or properly escaped.  Another potential problem is with
backup and restore jobs which may a) be using shell scripts to handle
file names and b) may be going to systems or media formats which don't
support these characters (e.g. many tape formats, ISO9660 compliant CD
issues mentioned earlier).

My personal preference is to not use spaces, but in cases where I have
lots of filenames with spaces, something like the following bash command
may help (tweaking may be required for other shells):

  $ for file in * ; do mv $file `echo $file | sed -e 's# #_#g'` ; done

This takes all files in the current directory and replaces spaces in
the file names with underscores.

Cheers,

Dan

-- 

A boast of "I have beens,"   | Daniel G. Epstein
quoted from foolscap tomes,  | Audio Engineer
is a shadow brushed away     |
by an acorn from an oak tree | Rootlike Technologies, Inc.
or a salmon in a pool.       | http://www.rootlike.com/

GnuPG public keys available from http://pgp.mit.edu/


[Subject index] [Index for current month] [Table of Contents]