On Saturday 31 December 2005 20:38, Matthias Bethke wrote: > Hi David, > > on Thursday, 2005-12-29 at 13:53:17, you wrote: > > > $(ls *.jpg) > > > > ick! > > > > (incidentally, http://www.ruhr.de/home/smallo/award.html#ls) > > Well, it's bad in two ways, and even the example on the above webpage > is wrong. For one thing, "ls" is useless here. For another, it will > break > > on spaces in filenames, unlike shell globbing: > | $ touch "foo bar.jpg" > | $ for f in *.jpg; do echo $f; done > | foo bar.jpg > | $ for f in `ls *.jpg`; do echo $f; done > | foo > | bar.jpg > | $ for f in `ls *.jpg`; do echo "$f"; done > | foo > | bar.jpg > > The bottommost try shows that the comment "newbies will often forget > the quotes, too" is wrong -- it won't work either way. If you have to > use > > a program that outputs a filename per line like ls, use a read loop: > | $ ls *.jpg | while read f; do echo "$f"; done > | foo bar.jpg > > The quotes are useless for "echo" here, but for other commands you'll > usually need them to keep the command form taking filenames with > sapaces as separate arguments. > > cheers! > Matthias
It is the first part of the command, the one expanding ls output that needs quotes... $ for f in $"`ls *.jpg`"; do echo $f; done foo bar.jpg Ciao Francesco -- Linux Version 2.6.14-gentoo-r6, Compiled #0 PREEMPT Sat Dec 31 01:17:32 CET 2005 One 1GHz AMD Athlon 64 Processor, 2GB RAM, 2007.23 Bogomips Total aemaeth -- gentoo-user@gentoo.org mailing list