Gentoo Archives: gentoo-amd64

From: Martin Herrman <martin@×××××××.nl>
To: gentoo-amd64@l.g.o
Subject: Re: [gentoo-amd64] How to use &&
Date: Sun, 04 Jan 2009 14:32:24
Message-Id: 40bb8d3b0901040632w288e13bauec56cd89d99253d6@mail.gmail.com
In Reply to: Re: [gentoo-amd64] How to use && by Paul Stear
1 On Sun, Jan 4, 2009 at 3:09 PM, Paul Stear <gentoo@××××××××××××.com> wrote:
2
3 > Thanks for your reply Martin. I have looked at your scripts and I might be
4 > able to use then in the future. My main problem is that my collection is so
5 > large, e.g 3104 files just in the directory beginning with "D" and that take
6 > about 4+ hours to run. So I could do with operating on 3 directories
7 > overnight.
8 > I must be able to add commands to be operated on in sequence.
9 >
10 > Any ideas?
11 >
12 > Paul
13
14 E.g. files are in /home/Fred Music/mp3; script is in /home/Fred
15 Music/script.sh; script is run from /home/Fred Music. The following
16 script would work (not tested!):
17
18 ======= script 1 ========
19 export IFS=$'\n'
20
21 for file in `find "/home/Fred Music/mp3" -type f -iregex '.*\.mp3'`;
22 do
23 mp3gain --auto "${file}"
24 done
25 ======== script 1 ==========
26
27 But: mp3gain is CPU-bound and this script won't use your 2 or 4 cores (right?)
28
29 You want to solve this by using &&, but this doesn't seem to work. &&
30 is just 'AND'. So A && B is true if and only if A is true and B is
31 true. So is the first command returns true, the second has to be
32 executed as well to verify if A && B is true. But if A is false, we
33 don't need to execute B, because A && B can never be true (because A
34 was already false).
35
36 Maybe your A doesn't return true?
37
38 But after all: this won't make use of your dual or quad core machine's power.
39
40 If you only have a single core available: use above 'script 1'. If you
41 have more cores available, you might want to use the idea that is used
42 in ogg2mp3:
43
44 ========= script 2 (pseudo code between ") =======
45
46 export IFS=$'\n'
47
48 function Gain {
49 "given left and right value, process(mp3gain) these elements of the
50 global array"
51 }
52
53 declare global array
54
55 for file in `find "/home/Fred Music/mp3" -type f -iregex '.*\.mp3'`;
56 do
57 "put file in the global array"
58 done
59
60 "divide array length among available cores"
61
62 i =0
63 while i < numcores do
64 "call function Gain" &
65 done
66
67 ========= script 2 =======
68
69 The "&" in the function call will create a child process and make it
70 use all your cores.
71
72 HTH,
73
74 Martin