* [gentoo-dev] Why don't they use -o in system scripts?
@ 2002-12-31 5:46 C. Linus Hicks
2003-01-03 9:59 ` Martin Schlemmer
0 siblings, 1 reply; 3+ messages in thread
From: C. Linus Hicks @ 2002-12-31 5:46 UTC (permalink / raw
To: gentoo-dev
I'm confused about why they use [ expression1 ] || [ expression2 ]
rather than [ expression1 -o expression2 ] in system scripts like
/etc/profile. It doesn't do the same thing, and I suppose the results
are usually the same. However, my read of the script is that what they
really want is a logical OR which is what the -o gives you.
--
C. Linus Hicks <lhicks@nc.rr.com>
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-dev] Why don't they use -o in system scripts?
2002-12-31 5:46 [gentoo-dev] Why don't they use -o in system scripts? C. Linus Hicks
@ 2003-01-03 9:59 ` Martin Schlemmer
2003-01-05 21:26 ` Phil Richards
0 siblings, 1 reply; 3+ messages in thread
From: Martin Schlemmer @ 2003-01-03 9:59 UTC (permalink / raw
To: C. Linus Hicks; +Cc: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1683 bytes --]
On 31 Dec 2002 00:46:00 -0500
"C. Linus Hicks" <lhicks@nc.rr.com> wrote:
> I'm confused about why they use [ expression1 ] || [ expression2 ]
> rather than [ expression1 -o expression2 ] in system scripts like
> /etc/profile. It doesn't do the same thing, and I suppose the results
> are usually the same. However, my read of the script is that what they
> really want is a logical OR which is what the -o gives you.
>
No offense, but I think you need to checkup on your bash again.
---------------------------
if [ -n $x ] && [ -n $y ]
then
echo "yes"
fi
---------------------------
are equivalent to:
---------------------------
if [ -n $x -a -n $y ]
then
echo "yes"
fi
---------------------------
Same goes for '-o'. '-o' and '-a' are just the
simpler forms of [ ] || [ ] and [ ] && [ ].
Also, with '-o' and '-a' you cannot do more
advance things like:
----------------------------------------------
if [ -n $x ] && ([ -n $y ] || [ -n $z ]) ...
----------------------------------------------
Although above you could have done:
----------------------------------------------
if [ -n $x ] && [ -n $y -o -n $z ] ...
----------------------------------------------
But then you still would need the '&&' in this case,
or a '||' in maybe some other case ...
You might have been thinking of:
----------------------------------------------
if [[ -n $x && -n $y || &z ]] .....
----------------------------------------------
in which case the first equation that returned true, would
have satisfied the equation, and are NOT the same as above
examples ....
Regards,
--
Martin Schlemmer
Gentoo Linux Developer, Desktop/System Team Developer
Cape Town, South Africa
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-dev] Why don't they use -o in system scripts?
2003-01-03 9:59 ` Martin Schlemmer
@ 2003-01-05 21:26 ` Phil Richards
0 siblings, 0 replies; 3+ messages in thread
From: Phil Richards @ 2003-01-05 21:26 UTC (permalink / raw
To: Martin Schlemmer; +Cc: gentoo-dev
On Fri, Jan 03, 2003 at 11:59:32AM +0200, Martin Schlemmer wrote:
> On 31 Dec 2002 00:46:00 -0500
> "C. Linus Hicks" <lhicks@nc.rr.com> wrote:
> > I'm confused about why they use [ expression1 ] || [ expression2 ]
> > rather than [ expression1 -o expression2 ] in system scripts like
> > /etc/profile. [...]
> No offense, but I think you need to checkup on your bash again.
[...]
> Same goes for '-o'. '-o' and '-a' are just the
> simpler forms of [ ] || [ ] and [ ] && [ ].
>
> Also, with '-o' and '-a' you cannot do more
> advance things like:
>
> ----------------------------------------------
> if [ -n $x ] && ([ -n $y ] || [ -n $z ]) ...
> ----------------------------------------------
Erm, yes you can:
if [ -n $x -a \( -n $y -o -n $z \) ] ...
[...]
> You might have been thinking of:
>
> ----------------------------------------------
> if [[ -n $x && -n $y || &z ]] .....
> ----------------------------------------------
>
> in which case the first equation that returned true, would
> have satisfied the equation, and are NOT the same as above
> examples ....
But,
if [[ -n $x && ( -n $y || -n $z ) ]] .....
is.
My preference is for the "[[ ... ]]" form - it tends to be more readable
(especially for people from a C/C++ background) and doesn't require
\-protection for nested "(...)" expressions.
There is no practical reason for not using either [-a/-o] or [[&&/||]]
in preference to the current approach.
However, it is purely a stylistic thing. There are no big wins
either way.
Anyway, the current /etc/profile uses both forms.
pihl
--
Phil Richards, <gentoo@derived-software.ltd.uk>
Derived Software Limited
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-01-05 21:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-31 5:46 [gentoo-dev] Why don't they use -o in system scripts? C. Linus Hicks
2003-01-03 9:59 ` Martin Schlemmer
2003-01-05 21:26 ` Phil Richards
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox