Gentoo Archives: gentoo-dev

From: Martin Schlemmer <azarah@g.o>
To: "C. Linus Hicks" <lhicks@×××××.com>
Cc: gentoo-dev@g.o
Subject: Re: [gentoo-dev] Why don't they use -o in system scripts?
Date: Sun, 05 Jan 2003 13:28:10
Message-Id: 20030103115932.3e67b077.azarah@gentoo.org
In Reply to: [gentoo-dev] Why don't they use -o in system scripts? by "C. Linus Hicks"
1 On 31 Dec 2002 00:46:00 -0500
2 "C. Linus Hicks" <lhicks@×××××.com> wrote:
3
4 > I'm confused about why they use [ expression1 ] || [ expression2 ]
5 > rather than [ expression1 -o expression2 ] in system scripts like
6 > /etc/profile. It doesn't do the same thing, and I suppose the results
7 > are usually the same. However, my read of the script is that what they
8 > really want is a logical OR which is what the -o gives you.
9 >
10
11 No offense, but I think you need to checkup on your bash again.
12
13 ---------------------------
14 if [ -n $x ] && [ -n $y ]
15 then
16 echo "yes"
17 fi
18 ---------------------------
19
20 are equivalent to:
21
22 ---------------------------
23 if [ -n $x -a -n $y ]
24 then
25 echo "yes"
26 fi
27 ---------------------------
28
29 Same goes for '-o'. '-o' and '-a' are just the
30 simpler forms of [ ] || [ ] and [ ] && [ ].
31
32 Also, with '-o' and '-a' you cannot do more
33 advance things like:
34
35 ----------------------------------------------
36 if [ -n $x ] && ([ -n $y ] || [ -n $z ]) ...
37 ----------------------------------------------
38
39 Although above you could have done:
40
41 ----------------------------------------------
42 if [ -n $x ] && [ -n $y -o -n $z ] ...
43 ----------------------------------------------
44
45 But then you still would need the '&&' in this case,
46 or a '||' in maybe some other case ...
47
48 You might have been thinking of:
49
50 ----------------------------------------------
51 if [[ -n $x && -n $y || &z ]] .....
52 ----------------------------------------------
53
54 in which case the first equation that returned true, would
55 have satisfied the equation, and are NOT the same as above
56 examples ....
57
58
59 Regards,
60
61 --
62
63 Martin Schlemmer
64 Gentoo Linux Developer, Desktop/System Team Developer
65 Cape Town, South Africa

Replies

Subject Author
Re: [gentoo-dev] Why don't they use -o in system scripts? Phil Richards <gentoo@××××××××××××××××××××.uk>