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

Re: Has a Debian developer ever unintentionally wiped out user files like Apple?



>>>>> "Ralph" == Ralph Jennings <ralph@oro.net> writes:

    Ralph> Not true..., UNIX users do know about the trouble
    Ralph> associated with buggy programs not able to handle spaces in
    Ralph> filenames, and so they try to make their programs work
    Ralph> correctly.

Part of the problem, IMHO, is how most shells parse spaces. Take
for instances this code:


FILE="A B"
cat $FILE

sh will process this in several steps (I am guessing at the details
here, especially with the execlp call, but the concept should be
correct):

0. "cat $FILE" 
1. "cat A B"                   (substitute $FILE)
2. "cat","A","B"               (split spaces)
3. execlp("cat","A","B",NULL)  (execute)

resulting in:

scrooge:~# A="A B"
scrooge:~# cat $A
cat: A: No such file or directory
cat: B: No such file or directory


zsh, on the other hand, won't split the environment variable after it
is substituted:

0. "cat $FILE" 
2. "cat","$FILE"               (split spaces)
1. "cat","A B"                 (substitute $FILE)
3. execlp("cat","A B",NULL)   (execute)

[501] [scrooge:bam] ~ >FILE="A B"
[502] [scrooge:bam] ~ >cat $FILE
cat: A B: No such file or directory


now of course, the obvious answer (as far as sh is concerned) is to
quote the $FILE and have cat "$FILE". However, that could have
undesirable side affects (as also mentioned in the ZSH documentation,
I can't recall the details now). For instance, in ZSH you can do this:

[525] [scrooge:bam] ~ >FILE=("A B" "B C")
[526] [scrooge:bam] ~ >cat $FILE         
cat: A B: No such file or directory
cat: B C: No such file or directory

which AFAIK, simply is not possible in sh unless you use multiple
variables.

For why this might be important, consider the special $* variable...

    Ralph> I am a UNIX person (administrator, programmer, etc...), and
    Ralph> I commonly use spaces in filenames.  I make sure that all
    Ralph> of my programs can handle spaces correctly.  And I file bug
    Ralph> reports on all programs I find that can't.

I never use spaces, partly because I don't trust my computer to cope
<grin>, and partly because it is harder to type the filenames in at
the command prompt.
-- 
Brian May <bam@debian.org>



Reply to: