[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Submitted: final draft of HOWTO



"
> > $ ./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 :

! condition
	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
command. 
A good set of examples illustrating the various possiblities might
include

        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.

-Pat

P.S. Is it time to bring back elephant jokes yet?



*


--  
To UNSUBSCRIBE, email to ldp-discuss-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org