Subject: Re: This has GOT to be a bug in ksh...
To: None <netbsd-users@netbsd.org>
From: Dan Riley <dsr@mail.lns.cornell.edu>
List: netbsd-users
Date: 06/16/2002 12:48:36
"ali \(Anders Lindgren\)" <dat94ali@ludat.lth.se> writes:
> .. and if it isn't, ksh is b0rken by design. ;-)

It's b0rken by design.

> $ touch "Berra =E4ter ost" "Lisa visar rattarna"
> $ for f in `find . -type f | sed -e 's/\(.*\)/"\1"/'` ; do echo $f ; do=
ne
> "./Berra
> =E4ter
> ost"
> "./Lisa
> visar
> rattarna"

Field splitting of command substitutions is *strictly* by IFS.  Quotes
don't matter, backslashes don't matter, it still gets split by IFS.
Unless the entire thing is in quotes, in which case no splitting is
done at all (so David S.'s proposal doesn't work--it looks right, but
if you change the echo to an ls, it's obvious that it isn't being
split at all, so all the filenames are one long parameter).  I believe
that Greg is right, no amount of manipulation will fix this.

A hideous kludge results from the observation that pathname expansion
happens after field splitting, so

for f in $(find . -type f | sed 's/ /?/g') ; do ls "$f" ; done

sortof works, until you have files named "a c" and "abc"--so that's
broken.  You could do something like

for f in $(find . -type f | sed 's/ /?/g') ; =

        do ls "$(echo $f | sed 's/\?/ /g')" ; done

With a little elaboration that could even be made to be correct, but
boy would it get ugly.  Or there's

( IFS=3D"
" ; for f in $(find . -type f) ; do ls "$f" ; done )

but I wouldn't really recommend that (I'm a little surprised it
even works).

In general, command substitution of arbitrary filenames is a can of
worms because the substitution is exposed to pathname expansion (do a
"touch '*'" and see what happens to those for loops).  Better to use
read as Greg suggests, or...

> (Yes, I usually try find -print0 ... xargs -0, and it usually doesn't
>  work for whatever it is I am trying to do for IRL situations)

I'd expect

find . -type f -print0 | xargs -0 -n1 mpg123

to work.  How does that fail IRL (aside from lack of portability)?
Or for that matter, good old

find . -type f -exec mpg123 {} \;

-dan