Gentoo Archives: gentoo-user

From: Francesco Talamona <ti.liame@×××××.it>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: [OT] Filename modification with suffix
Date: Sat, 31 Dec 2005 21:11:33
Message-Id: 200512312204.59398.ti.liame@email.it
In Reply to: Re: [gentoo-user] [OT] Filename modification with suffix by Matthias Bethke
1 On Saturday 31 December 2005 20:38, Matthias Bethke wrote:
2 > Hi David,
3 >
4 > on Thursday, 2005-12-29 at 13:53:17, you wrote:
5 > > > $(ls *.jpg)
6 > >
7 > > ick!
8 > >
9 > > (incidentally, http://www.ruhr.de/home/smallo/award.html#ls)
10 >
11 > Well, it's bad in two ways, and even the example on the above webpage
12 > is wrong. For one thing, "ls" is useless here. For another, it will
13 > break
14 >
15 > on spaces in filenames, unlike shell globbing:
16 > | $ touch "foo bar.jpg"
17 > | $ for f in *.jpg; do echo $f; done
18 > | foo bar.jpg
19 > | $ for f in `ls *.jpg`; do echo $f; done
20 > | foo
21 > | bar.jpg
22 > | $ for f in `ls *.jpg`; do echo "$f"; done
23 > | foo
24 > | bar.jpg
25 >
26 > The bottommost try shows that the comment "newbies will often forget
27 > the quotes, too" is wrong -- it won't work either way. If you have to
28 > use
29 >
30 > a program that outputs a filename per line like ls, use a read loop:
31 > | $ ls *.jpg | while read f; do echo "$f"; done
32 > | foo bar.jpg
33 >
34 > The quotes are useless for "echo" here, but for other commands you'll
35 > usually need them to keep the command form taking filenames with
36 > sapaces as separate arguments.
37 >
38 > cheers!
39 > Matthias
40
41 It is the first part of the command, the one expanding ls output that
42 needs quotes...
43
44 $ for f in $"`ls *.jpg`"; do echo $f; done
45 foo bar.jpg
46
47 Ciao
48 Francesco
49 --
50 Linux Version 2.6.14-gentoo-r6, Compiled #0 PREEMPT Sat Dec 31 01:17:32
51 CET 2005
52 One 1GHz AMD Athlon 64 Processor, 2GB RAM, 2007.23 Bogomips Total
53 aemaeth
54 --
55 gentoo-user@g.o mailing list

Replies

Subject Author
[gentoo-user] Re: [OT] Filename modification with suffix Francesco Talamona <ti.liame@×××××.it>