1 |
Nirbheek Chauhan wrote: |
2 |
|
3 |
> On Wed, Dec 24, 2008 at 9:50 PM, Doug Goldstein <cardoe@g.o> wrote: |
4 |
>> Nirbheek Chauhan wrote: |
5 |
> [snip] |
6 |
>>> commands that die: |
7 |
>>> everything that is implemented as a function (ebuild.sh, eclasses, etc) |
8 |
> [snip] |
9 |
>> |
10 |
>> Technically the rule is that eclasses shouldn't die. At least that's the |
11 |
>> latest version of the rules that I remember. |
12 |
>> |
13 |
> |
14 |
> eclasses shouldn't die or functions inside eclasses shouldn't die? I |
15 |
> meant the latter: |
16 |
> |
17 |
> s/(ebuild.sh/(inside ebuild.sh/ |
18 |
> |
19 |
The only technical reason not to allow an --or-die (or the equivalent) |
20 |
switch for everything is the issues with subshell die, for which I sent |
21 |
some script to test but didn't hear back about, but more cogently that old |
22 |
GNU heads think xargs is necessary as GNU find didn't implement -exec |
23 |
correctly (according to POSIX) until a couple of years ago. |
24 |
|
25 |
In BASH, one would use the equivalent loop (which will cope with any |
26 |
filename): |
27 |
while read -rd '' f; do foo --or-die "$f"; done < <(find .. -print0) |
28 |
|
29 |
I usually show newbs this: |
30 |
while read -rd ''; do arr+=("$REPLY"); done < <(find .. -print0) |
31 |
..since it shows a bit more about read and gives the other usual |
32 |
requirement. |
33 |
|
34 |
This is compatible with the old broken GNU find as well as BSD, but -print0 |
35 |
is not required by POSIX. |
36 |
|
37 |
I'm sure I've used that in a function somewhere amongst one of the patches I |
38 |
filed with someone or the other. TBH a professional BASH scripter would |
39 |
sneer (I can think of several) at needing to wrap it in a function: it's |
40 |
like not knowing how to read a file line-by-line in POSIX sh. |
41 |
|
42 |
Put it this way: if you actually need the filenames, or some other |
43 |
information elsewhere in the script[1], chances are that the loop has more |
44 |
meat to it. |
45 |
|
46 |
I suppose you could pass directories and params for a find command/API |
47 |
function, eg: |
48 |
findE --or-die foo dirA/b dirC/d ! \( -type -l -o -name '*~' \) |
49 |
..or the like, showing --or-die first for consistency but it could of course |
50 |
come anywhere. |
51 |
|
52 |
[1] /msg greybot faq disappear |