1 |
On Fri, Jan 03, 2003 at 11:59:32AM +0200, Martin Schlemmer wrote: |
2 |
> On 31 Dec 2002 00:46:00 -0500 |
3 |
> "C. Linus Hicks" <lhicks@×××××.com> wrote: |
4 |
> > I'm confused about why they use [ expression1 ] || [ expression2 ] |
5 |
> > rather than [ expression1 -o expression2 ] in system scripts like |
6 |
> > /etc/profile. [...] |
7 |
> No offense, but I think you need to checkup on your bash again. |
8 |
[...] |
9 |
> Same goes for '-o'. '-o' and '-a' are just the |
10 |
> simpler forms of [ ] || [ ] and [ ] && [ ]. |
11 |
> |
12 |
> Also, with '-o' and '-a' you cannot do more |
13 |
> advance things like: |
14 |
> |
15 |
> ---------------------------------------------- |
16 |
> if [ -n $x ] && ([ -n $y ] || [ -n $z ]) ... |
17 |
> ---------------------------------------------- |
18 |
|
19 |
Erm, yes you can: |
20 |
|
21 |
if [ -n $x -a \( -n $y -o -n $z \) ] ... |
22 |
|
23 |
[...] |
24 |
> You might have been thinking of: |
25 |
> |
26 |
> ---------------------------------------------- |
27 |
> if [[ -n $x && -n $y || &z ]] ..... |
28 |
> ---------------------------------------------- |
29 |
> |
30 |
> in which case the first equation that returned true, would |
31 |
> have satisfied the equation, and are NOT the same as above |
32 |
> examples .... |
33 |
|
34 |
But, |
35 |
|
36 |
if [[ -n $x && ( -n $y || -n $z ) ]] ..... |
37 |
|
38 |
is. |
39 |
|
40 |
My preference is for the "[[ ... ]]" form - it tends to be more readable |
41 |
(especially for people from a C/C++ background) and doesn't require |
42 |
\-protection for nested "(...)" expressions. |
43 |
|
44 |
There is no practical reason for not using either [-a/-o] or [[&&/||]] |
45 |
in preference to the current approach. |
46 |
|
47 |
However, it is purely a stylistic thing. There are no big wins |
48 |
either way. |
49 |
|
50 |
Anyway, the current /etc/profile uses both forms. |
51 |
|
52 |
pihl |
53 |
|
54 |
-- |
55 |
Phil Richards, <gentoo@××××××××××××××××××××.uk> |
56 |
Derived Software Limited |
57 |
|
58 |
-- |
59 |
gentoo-dev@g.o mailing list |