From owner-freebsd-questions Thu Jun 28 21:25:42 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mtiwmhc22.worldnet.att.net (mtiwmhc22.worldnet.att.net [204.127.131.47]) by hub.freebsd.org (Postfix) with ESMTP id 36FDF37B406 for ; Thu, 28 Jun 2001 21:25:39 -0700 (PDT) (envelope-from parv@worldnet.att.net) Received: from worldnet.att.net ([32.101.235.185]) by mtiwmhc22.worldnet.att.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20010629042537.CKOO13460.mtiwmhc22.worldnet.att.net@worldnet.att.net>; Fri, 29 Jun 2001 04:25:37 +0000 Received: by worldnet.att.net (Postfix, from userid 1001) id 5D38619313; Fri, 29 Jun 2001 00:27:58 -0400 (EDT) Date: Fri, 29 Jun 2001 00:27:58 -0400 From: parv To: Dave Tweten Cc: freebsd-questions@freebsd.org Subject: Re: Bourne Shell Syntax Wierdness Message-ID: <20010629002758.A3157@moo.holy.cow> Mail-Followup-To: Dave Tweten , freebsd-questions@freebsd.org References: <200106290144.f5T1itu01729@gilmore.nas.nasa.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200106290144.f5T1itu01729@gilmore.nas.nasa.gov>; from tweten@nas.nasa.gov on Thu, Jun 28, 2001 at 06:44:54PM -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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