From owner-freebsd-questions@FreeBSD.ORG Tue May 20 09:30:48 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7B521065676 for ; Tue, 20 May 2008 09:30:48 +0000 (UTC) (envelope-from jonathan@hst.org.za) Received: from hermes.hst.org.za (onix.hst.org.za [209.203.2.133]) by mx1.freebsd.org (Postfix) with ESMTP id C6A5E8FC31 for ; Tue, 20 May 2008 09:30:46 +0000 (UTC) (envelope-from jonathan@hst.org.za) Received: from sysadmin.hst.org.za (sysadmin.int.dbn.hst.org.za [10.1.1.20]) (authenticated bits=0) by hermes.hst.org.za (8.13.8/8.13.8) with ESMTP id m4K9SZjA085005 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 20 May 2008 11:28:35 +0200 (SAST) (envelope-from jonathan@hst.org.za) From: Jonathan McKeown Organization: Health Systems Trust To: freebsd-questions@freebsd.org Date: Tue, 20 May 2008 11:33:50 +0200 User-Agent: KMail/1.7.2 References: <7d6fde3d0805190149y7a3bfa75j2ca6a67cef66e8f6@mail.gmail.com> <20080519094603.GC12033@osiris.chen.org.nz> <20080520014133.3447c282@gumby.homeunix.com.> In-Reply-To: <20080520014133.3447c282@gumby.homeunix.com.> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805201133.50963.jonathan@hst.org.za> X-Spam-Score: -4.378 () ALL_TRUSTED,AWL,BAYES_00 X-Scanned-By: MIMEDefang 2.61 on 209.203.2.133 Subject: Re: Now what would you expect this to print out? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 May 2008 09:30:48 -0000 On Tuesday 20 May 2008 02:41, RW wrote: > On Mon, 19 May 2008 21:46:03 +1200 > > Jonathan Chen wrote: > > On Mon, May 19, 2008 at 01:49:35AM -0700, Garrett Cooper wrote: > > > Riddle for the day for folks that have source trees... what would > > > you expect this to print out (ask yourself the question and then > > > execute the command)? > > > > > > find /usr/src -name Makefile -or -name '*.mk' -print > > > > > > The expected output and what actual output differed in my mind, but > > > maybe somebody else can "shed some light" on the logic behind what > > > happened > > > > It's a problem that catches many young players with find(1). One has > > to remember from reading the man-page that all directives have an > > implicit AND operator on it; and that includes the "-print" directive. > > So to get what you want, you have to introduce brackets: > > > > find /usr/src \( -name Makefile -or -name '*.mk' \) -print > > Why does that make a difference, when print always evaluates to true? > > x AND true = x > > so > > (a OR b) AND true = a OR b > a OR (b AND true) = a OR b It makes a difference (as in programming) because -print is used for its side-effect rather than its value, and the binding order influences when the side-effect happens. Jonathan