From owner-freebsd-questions Fri Jun 29 0:32:57 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-27-141-144.mmcable.com [24.27.141.144]) by hub.freebsd.org (Postfix) with SMTP id 9272737B405 for ; Fri, 29 Jun 2001 00:32:52 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 49966 invoked by uid 100); 29 Jun 2001 07:32:51 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15164.12067.829448.734806@guru.mired.org> Date: Fri, 29 Jun 2001 02:32:51 -0500 To: Dave Tweten Cc: questions@freebsd.org Subject: Re: Bourne Shell Syntax Wierdness In-Reply-To: <98860201@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ 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 Dave Tweten types: > 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!" The || and && operators are left associative, so that your example - which is ambiguous given only the information you provided - is parsed as "( true || true ) && echo Oops!". Since "( true || true )" always terminates normally, it should print "echo 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. But it matches the way most people read expressions. The world would be a better place if we switched to an unambiguous system for mathematical expressions :-). > Incidently, "true || { true && echo Oops! }" prints nothing -- which > I would have expected with or without the "{}". That's what would happen if the operators were right associative instead of left associative - which would collide with most peoples expectations based on common mathematical usage. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message