Gentoo Archives: gentoo-dev

From: Roy Marples <uberlord@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Re: Re: Re: [gentoo-commits] gentoo-x86 commit in dev-php5/onphp: ChangeLog onphp-0.10.6.ebuild onphp-0.10.4.ebuild onphp-0.10.3.ebuild
Date: Tue, 16 Oct 2007 14:21:17
Message-Id: 1192543696.1173.18.camel@uberlaptop.development.ltl
In Reply to: [gentoo-dev] Re: Re: Re: [gentoo-commits] gentoo-x86 commit in dev-php5/onphp: ChangeLog onphp-0.10.6.ebuild onphp-0.10.4.ebuild onphp-0.10.3.ebuild by Steve Long
1 On Tue, 2007-10-16 at 13:38 +0100, Steve Long wrote:
2 > Roy Marples wrote:
3 > > On Tue, 2007-10-16 at 00:28 -0700, Donnie Berkholz wrote:
4 > >> On 08:19 Tue 16 Oct , Steve Long wrote:
5 > >> > stdDocs=(ChangeLog AUTHORS FEATURES THANKS README CodingStyle TODO FAQ)
6 > >> >
7 > >> > stdDoc() {
8 > >> > local d l=()
9 > >> > for d in "${stdDocs[@]}"; do
10 > >> > [[ -f $d ]] && l+=("$d")
11 > >> > done
12 > >> > ((${#l[@]})) && dodoc "${l[@]}"
13 > >> > }
14 > >> >
15 > >> > (assuming [[ $PWD = $S ]] or whichever is the right one for docs.)
16 > >>
17 > >> Is it just me, or is this code way more complex than it needs to be? It
18 > >> looks like bashturbation to me. =P
19 > >
20 > LMAO. It's as complex as it needs to be to handle filenames with spaces or
21 > any other character in. Remember: "Looks like it needs quotes there.. $D,
22 > $S.." What, I should write crap script for this esteemed audience, cos you
23 > only currently deal with filenames without spaces? ;P
24
25 No, it's overly complex. Consider this
26
27 stddoc() {
28 local d
29 for d in ChangeLog AUTHORS FEATURES THANKS README \
30 CodingStyle TODO FAQ; do
31 [ -f "${d}" ] && dodoc "${f}"
32 done
33 }
34
35 Want spaces?
36
37 stddoc() {
38 local d
39 for d in ChangeLog AUTHORS FEATURES THANKS README \
40 CodingStyle TODO FAQ "a file with spaces"; do
41 [ -f "${d}" ] && dodoc "${f}"
42 done
43 }
44
45 Or maybe you want to do it on one hit?
46
47 stddoc() {
48 local d
49 set --
50 for d in ChangeLog AUTHORS FEATURES THANKS README \
51 CodingStyle TODO FAQ "a file with spaces"; do
52 [ -f "${d}" ] && set -- "$@" "${f}"
53 done
54 dodoc "$@"
55 }
56
57
58 > > You can also do some pattern matching like so
59 > >
60 > > foo="foo foobar"
61 > >
62 > > [ "${foo%foobar}" = "${foo}" ] || echo "ends with foobar"
63 > [[ $foo = *foobar ]] && echo "ends with foobar"
64 >
65 > > [ "${foo#foobar}" = "${foo}" ] || echo "starts with foo"
66 > [[ $foo = foo* ]] && echo 'oh does it?'
67 > There's no need for borked script that is counter-intuitive, and doesn't
68 > have a third of the functionality either.
69
70 I maybe wrong, but shouldn't you be using == inside [[ ]]?
71
72 > [[ $foo = *'wow it '*"does as $well"* ]] && echo 'And a whole lot more!'
73
74 case "${foo}" in
75 *'wow it '*"does as $well"*) && echo "whatever you can do i can do in
76 sh";;
77 esac
78
79 > Or should *nix only ever support
80 > POSIX APIs for everything? #define _X_OPEN_SOURCE? No? Hmm.. *shrug* ;>
81
82 No, I saying use whatever god given extensions you like. But if there's
83 a portable way of doing the same thing then please use the portable way
84 of doing it.
85
86 > /me wanders down the pub.. *plop*
87
88 Yeah, I'd drown my sorrows if I wrote shell script like you :P
89
90 Thanks
91
92 Roy
93
94 --
95 gentoo-dev@g.o mailing list

Replies