Date: Fri, 29 Jun 2001 00:27:58 -0400 From: parv <parv_@yahoo.com> To: Dave Tweten <tweten@nas.nasa.gov> Cc: freebsd-questions@freebsd.org Subject: Re: Bourne Shell Syntax Wierdness Message-ID: <20010629002758.A3157@moo.holy.cow> In-Reply-To: <200106290144.f5T1itu01729@gilmore.nas.nasa.gov>; from tweten@nas.nasa.gov on Thu, Jun 28, 2001 at 06:44:54PM -0700 References: <200106290144.f5T1itu01729@gilmore.nas.nasa.gov>
next in thread | previous in thread | raw e-mail | index | archive | help
so, Dave Tweten shared this in my lifetime... > The sh man page says that the two operators "||" and "&&" have the same > precedence. It also says that > > a || b > > means "execute b if a terminates abnormally" and > > a && b > > means "execute b if a terminates normally." > > So I don't understand why > > true || true && echo Oops! > > prints "Oops!" > > 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. > > Incidently, > > true || { true && echo Oops! } > > prints nothing -- which I would have expected with or without the "{}". > sh & ksh man pages do say the quoted behaviour above. so does bash's. however, bash's page adds this, under "Compund Commands" which is missing for sh & ksh: The && and || operators do not execute expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression. notice the word "sufficient"; so due to lack of proper grouping, to mitigate ambiguity, all three evaluates the expression as... # ( true || true ) && echo Oops! ...i may be stating the obvious; mind you that i am only hypothisizing here, nothing more than that, lest somebody is bent on getting the above desired evaluation... -- so, do you like word games or scrabble? - parv To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010629002758.A3157>