1 |
On Wednesday, October 13, 2010 03:08:24 Vaeth wrote: |
2 |
> Mike Frysinger wrote: |
3 |
> > > for foo in ${ROOT}/etc/openvpn/*/local.conf; do |
4 |
> > > |
5 |
> > > [ -e ${foo} ] && bar ${foo} |
6 |
> > > |
7 |
> > > done |
8 |
> > |
9 |
> > i'd say doing a loop is worse than a `ls` hack. |
10 |
> |
11 |
> Why do you think so? No external program on which you must rely, |
12 |
> and if you put a "break" in there, the loop is just syntactical. |
13 |
> Here is another possibility if you do not need positional |
14 |
> parameters anymore: |
15 |
> |
16 |
> set -- "${ROOT}"/etc/openvpn/*/local.conf |
17 |
> if test -e "${1}" |
18 |
> then ... |
19 |
> fi |
20 |
> |
21 |
> And if you do need, you can write a function: |
22 |
> |
23 |
> Test2() { |
24 |
> test "${1}" "${2}" |
25 |
> } |
26 |
> |
27 |
> if Test2 -e "${ROOT}"/etc/openvpn/*/local.conf |
28 |
> then ... |
29 |
> fi |
30 |
|
31 |
relying on an external program to get a single line of readable code is better |
32 |
than multiple lines of code that attempt to do the same thing. your further |
33 |
examples here are even worse on many levels. |
34 |
-mike |