[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Submitted: final draft of HOWTO
- To: "M. Leo Cooper" <firstname.lastname@example.org>, Bodvar Bjorgvinsson <email@example.com>, digs <firstname.lastname@example.org>, Aaron King <email@example.com>, Juan Fuentes <firstname.lastname@example.org>, Mike Novack <email@example.com>, ngcooper <firstname.lastname@example.org>, "Lonnie R. Mullenix" <email@example.com>, Nick Sklavenitis <firstname.lastname@example.org>, Sam <email@example.com>, "firstname.lastname@example.org" <email@example.com>
- Subject: Re: Submitted: final draft of HOWTO
- From: Patrick Callahan <firstname.lastname@example.org>
- Date: Tue, 25 Jul 2000 19:45:16 -0400
- References: <Pine.LNX.4.20.0007242356480.611-100000@localhost>
- Resent-date: Tue, 25 Jul 2000 19:45:34 -0400 (EDT)
- Resent-from: email@example.com
- Resent-message-id: <tXC0aB.A.D1.Mbif5@murphy>
- Resent-sender: firstname.lastname@example.org
- Sender: pac1
> > $ ./a_if3.sh
> > not i or not j
> I got:
> i=1 and j=2
> as the output, which is consistent with what you write, below.
Sorry, got sloppy. and pasted in the wrong thing.
> I was unaware of the -a and -o comparison operators. These seem to be
> undocumented. Again, this is worthy of inclusion in an update of the HOWTO.
-a and -o are documented in the Bash Reference manual in Chapter 4,
Bourne Shell Builtins. see the topic "test".
O'Reilly's Nutshell book has it in their chapter 4, Bash: The Bourne
Again Shell, in the section Built In Commands, under the topic Test with
the sub-heading Combined Forms.
The three forms are :
True if the condition is false
condition1 -a condition2
True if both conditions are true
condition1 -o condition2
True if either condition is true
The thing to point out about if in bash is that if evaluates just about
anything as if it were a condition, but bash itself does not have a
native language for computation of conditional values beyond && and ||.
I think Bash itself actually does not have a comparison operator like
==. This means that although conditions can be represented as values of
variables, and the values of variables can be operated on by && and ||,
and the result can be evaluated by if, constructs that compare values
are not written in the language of bash but in the language of the test
A good set of examples illustrating the various possiblities might
use of if to evaluate an integer
use of if to evaluate a string
use of if to evaluate a command which succeeds
use of if to evaluate a command which fails
use of if to evaluate improper bash syntax
use of if to evaluate a construct using &&
use of if to evaluate a construct using ||
use of if to evaluate the results of test with
comparison of two strings
comparison of two integers
existence test for a file
an expression including -o
an expression including -a
an expression including !
combining &&, || and test in the same expression
> I certainly don't claim to be an expert in all the minutiae of Bash and its
> use. That is precisely why input from the readers of the HOWTO is important,
> so that errors and omissions in the document may be corrected.
To borrow an image from an old story about blind men describing an
elephant, "We're all bozos in the bash circus and each of us has hold of
a different part of the elephant."
> Again, thanks for your comments.
You're welcome. And thank you for your work on the howto.
P.S. Is it time to bring back elephant jokes yet?
To UNSUBSCRIBE, email to email@example.com
with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org