From: Phil Richards <gentoo@derived-software.ltd.uk>
To: Martin Schlemmer <azarah@gentoo.org>
Cc: gentoo-dev@gentoo.org
Subject: Re: [gentoo-dev] Why don't they use -o in system scripts?
Date: Sun, 5 Jan 2003 21:26:55 +0000 [thread overview]
Message-ID: <20030105212655.GA19831@derisoft.derived-software.demon.co.uk> (raw)
In-Reply-To: <20030103115932.3e67b077.azarah@gentoo.org>
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
prev parent reply other threads:[~2003-01-05 21:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030105212655.GA19831@derisoft.derived-software.demon.co.uk \
--to=gentoo@derived-software.ltd.uk \
--cc=azarah@gentoo.org \
--cc=gentoo-dev@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox