[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: Sun, 23 Jul 2000 21:11:53 -0400
- References: <Pine.LNX.4.20.0007231328270.602-100000@localhost>
- Resent-date: Sun, 23 Jul 2000 21:11:33 -0400 (EDT)
- Resent-from: email@example.com
- Resent-message-id: <rIBshC.A.p-H.wf5e5@murphy>
- Resent-sender: firstname.lastname@example.org
- Sender: pac1
"M. Leo Cooper" wrote:
> I have submitted the final draft of my "Advanced Bash-Scripting HOWTO",
> version 0.1, to the group by sending it as as a tarballed file attachment
> to ldp-submit.
> This document is also downloadable from my web site:
> [125 k]
> The tarball on my site also has the HTML conversion of the document. The
> document itself is, of course, in Docbook/SGML, thanks to Philippe Martin.
> Any comments and constructive criticism would be appreciated.
I've used the abs-HOWTO-0.1 today. It's an excellent tutorial on bash,
and has allowed me to clarify the meaning of one of the language
elements of bash I'd been struggling with after reading only the
Reference Manual, indirect references.
Another language element continues to give me trouble. It is the
combination of conditions in an if statement, and the tutorial does not
go into enough specifics on this point.
Using && to join two "conditions" does not work as "expected" when the
elements combined with && and || are not variables, but "conditions".
There's an element of syntax that I'm missing to make Example A work
correctly, and no reference I've been able to find shows what it is or
explains the difference between && and || on one hand and -a and -o on
the other. I think your howto would be an excellent place to get into
# using && to join "conditions" as shown does not work properly
if [ i -eq 1 && j -eq 2 ]
echo "i=1 and j=2"
echo "i<> 1 or j<> 2"
$ chmod +x a_if.sh
./a_if.sh: [: missing `]'
i<> 1 or j<> 2
note the error message and incorrect operation in the version of the
script using && to join two "conditions"
# using -a to join two conditions using "and" does work properly
if [ $i -eq 1 -a $j -eq 2 ]
echo "i=1 and j=2"
echo "i<> 1 or j<> 2"
not i or not j
This use of -a or -o working in the above construct seems to conflict
with the following from the bash manual and from the HOWTO. I think an
explanation of what is really happening in this case would enhance the
HOWTO. To most of us from other programming environments $i -eq 1 looks
like a condition, so we need an explanation of why the construct as
written in example A does not work while the construct in example B does
not. I'm assuming the construct works if the conditions are "variables"
and not conditional expressions, at least conditional expressions as
written in Example A: We need advice on what exact syntax to use to
accomplish the intent expressed in example A. If && and || are limited
to being used as operators on variables that's ok. If there's a way to
write a conditional expression using actual conditional expressions that
will be properly combined using && or || we'll need an example of that
What we have in the Bash Reference and the HOWTO does not address this
issue properly, or if it does, the information is not presented in an
order that will allow it to be found easily.
if [ $condition1 && $condition2 ]
# if both condition1 and condition2 hold true...
if [ $condition1 || $condition2 ]
# if both condition1 or condition2 hold true...
To UNSUBSCRIBE, email to email@example.com
with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org