Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2001 23:32:37 -0400
From:      Pete Fritchman <petef@databits.net>
To:        Dave Tweten <tweten@nas.nasa.gov>
Cc:        freebsd-doc@freebsd.org
Subject:   Re: Fw: Re: Bourne Shell Syntax Wierdness
Message-ID:  <20010628233237.A81983@databits.net>
In-Reply-To: <200106290209.f5T29Hu01819@gilmore.nas.nasa.gov>; from tweten@nas.nasa.gov on Thu, Jun 28, 2001 at 07:09:16PM -0700
References:  <200106290209.f5T29Hu01819@gilmore.nas.nasa.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
++ 28/06/01 19:09 -0700 - Dave Tweten:
| > The sh man page says that the two operators "||" and "&&" have the same 
| > precedence.
 [ snip ]
| > So I don't understand why
| > 
| > 	true || true && echo Oops!
| > 
| > prints "Oops!"

"They have the same precedence."  In math, "+" and "-" have the same
precedence.  So, if you have 1 + 2 + 3, you evaluate 1 + 2, then you
evaulate that result + 3.

true || true && echo Oops!

you first take 'true || true' -- you end up with true.  you then eval
'&& echo Oops!' with the result of 'true || true' (true). true always
exits sucessfully, so the command after && is executed and you see
'Oops!'  Does this sound right?  It makes sense in my head, but I'm not
sure if I'm explaining it right. 

| > 
| > This is apparently not a bug in FreeBSD sh, because IRIX, IRIX64, and SunOS 
| > Bourne/Korn shells work the same way, but it certainly runs counter to my 
| > ability to read English and the contents of the man page.
| > 

-pete

--
Pete Fritchman <petef@databits.net>
Databits Network Services, Inc. <http://databits.net>;
finger petef@databits.net for PGP key


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-doc" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010628233237.A81983>