1 |
Ulrich Mueller wrote: |
2 |
|
3 |
>>>>>> On Mon, 22 Sep 2008, Kent Fredric wrote: |
4 |
> |
5 |
>> find /usr/share/doc/ -wholename "* *" |
6 |
>> /usr/share/doc/gpac-0.4.4-r1/ISO 639-2 codes.txt.bz2 |
7 |
> |
8 |
> Yes, and if you look into src_install of the ebuild, it does: |
9 |
> dodoc doc/*.txt |
10 |
> |
11 |
Well at least we've established that it can and does happen. |
12 |
|
13 |
> So a simple "dodoc ${DOCS}" with DOCS="... doc/*.txt ..." would work |
14 |
> even in this case. No need for arrays. |
15 |
> |
16 |
That works for that specific case, yes, but it's still not a general |
17 |
solution, which is what BASH arrays were invented for. For instance, an |
18 |
ebuild author cannot specifically include a file with spaces, and ignore |
19 |
all the other files in the same directory. |
20 |
|
21 |
To show what I mean, given this one-liner in a terminal: |
22 |
args() { (($#)) || return; echo "$# params:"; local i n=1; for i; do |
23 |
echo "$n: $i"; let n++; done; } |
24 |
|
25 |
..try these (where doc is a subdirectory of your current folder, and mem* |
26 |
matches some files in it): |
27 |
DOCS="doc/mem* foo"; args $DOCS |
28 |
DOCS="doc/mem* 'foo bar baz'"; args $DOCS |
29 |
DOCS=(doc/mem* 'foo bar baz'); args "${DOCS[@]}" |
30 |
|
31 |
Globs work fine for a function call, or indeed for adding to an array. As |
32 |
soon as you try to indirect via a variable, it has to be an array if you |
33 |
want to be safe with filenames, for the general case. The same applies to |
34 |
dynamic commands. See: |
35 |
http://wooledge.org:8000/BashFAQ/040 and: |
36 |
http://wooledge.org:8000/BashFAQ/050 |
37 |
|
38 |
Given that we're using BASH, it seems strange to preclude useful constructs. |
39 |
It's a bit like telling someone to use Python without dicts (or even lists, |
40 |
given how basic arrays are to virtually every programming language.) It's |
41 |
much simpler to write scripts that will work with anything, and be able to |
42 |
rely on them, than have to fix or work round them later. |