tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ question about chmod

Files with space ▻

Files with space

In article <80e69d$hco$1@nnrp1.deja.com>,
Johnathan  <newsbuzz@my-deja.com> wrote:
>                                                Unix don't quite
>like file names with funny symbols

I'm in quibbling mode, so...

In fact, Unix is extrememly liberal with characters in file names.  A
path component may contain any character except `/' or NUL.  (Compare
with Windows, where file names may not contain any of [\/:*?"<>|].)

The problem, of course, is that the shell (and other programs like
`xargs') use the space character to *separate* file names.  With the
Bourne shell and its derivatives, it's harder than it ought to be to
write shell scripts that can handle file names that contain spaces.  With
care, it can be done, but it often isn't.

There's a vicious circle here: Unix users tend to avoid creating file
names that contain spaces, since they know they can cause problems; Unix
programmers sometimes forget to handle file names that contain spaces,
since they don't often encounter them.

Regular readers will have realized that there must be an advert for rc
here somewhere...

    ; > 'foo bar'
    ; for (i in *) ls $i
    foo bar
    ; sh
    $ for i in *; do ls $i; done
    ls: foo: No such file or directory
    ls: bar: No such file or directory

Tim.
--
Tim Goodwin   | "People think [ W. Gibson is ] hi-tech because his prose
Leicester, UK | is as pleasant to read as a C++ program." -- JT

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: Files with space
Date: 12 Nov 1999 15:45:28 -0000
Organization: University of Leicester, UK
Message-ID: <80hcne$b5d$1@ltpcg.star.le.ac.uk>
References: <80c4uc$15p$1@nnrp1.deja.com> <3829AB22.22FA410B@cat.com>
  <3829BFC0.4E79CB03@austin.ibm.com> <80e69d$hco$1@nnrp1.deja.com>

△ comp.unix.shell △

◅ question about chmod

Files with space ▻