Subject: Re: This has GOT to be a bug in ksh...
To: ali \(Anders Lindgren\) <dat94ali@ludat.lth.se>
From: Ben Collver <collver1@attbi.com>
List: netbsd-users
Date: 06/17/2002 08:29:21
On Sun, Jun 16, 2002 at 03:23:05PM +0200, ali (Anders Lindgren) wrote:
> .. and if it isn't, ksh is b0rken by design. ;-)
> 
> I frequently come across a certain type of compressed audio files *cough*
> with spaces in their filenames, and I frequently wish to feed them to
> an audio-player one by one (because mpg123 is buggy) and being a lazy bum,
> I like to just fiddle something together on the commandline. 
> 
> Now, this shouldn't pose a problem even to the moderately
> shell-programming skilled person such as yours truly. Yet I find
> myself tearing my hair again and again. I now sat down to figure
> out exactly wtf the problem is. Trivial, non-typical demonstration:
> 
> $ for f in "Berra äter ost" "Lisa visar rattarna" ; do echo $f ; done
> "Berra äter ost"
> "Lisa visar rattarna"
> $
> 
> ok, great. So it *should* work. So let's do it on files then! Ergo:
> 
> $ touch "Berra äter ost" "Lisa visar rattarna"
> $ for f in `find . -type f | sed -e 's/\(.*\)/"\1"/'` ; do echo $f ; done
> "./Berra
> äter
> ost"
> "./Lisa
> visar
> rattarna"
> $
> 
> err... what the fsck? Hrrm, ok, maybe ksh gets confused by them newlines
> in between the quoted names that "find" inserts. Let's try to remove them:
> 
> $ for f in `find . -type f | sed -e 's/\(.*\)/"\1"/' | tr '\n' ' '` ; do
> echo $f ; done
> "./Berra
> äter
> ost"
> "./Lisa
> visar
> rattarna"
> $
> 
> Ehm. This can't be right. Did I do a typo somewhere? Better check:
> 
> $ find . -type f | sed -e 's/\(.*\)/"\1"/' | tr '\n' ' '
> "./Berra äter ost" "./Lisa visar rattarna" $
> 
> Hrrm apparently not. This is insane. Let's bother netbsd-users about
> it. ;-)
> 
> Any ideas? I can't believe no-one has stumbled into this before. 
> (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)
> 
> -- 
> /ali
> :wq

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

try:
$ for f in "`find . -type f | sed -e 's/\(.*\)/"\1"/'`"; do echo $f; done

Ben