From owner-freebsd-chat@FreeBSD.ORG Sun Jul 12 22:30:03 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A771106566C for ; Sun, 12 Jul 2009 22:30:03 +0000 (UTC) (envelope-from jcw@highperformance.net) Received: from mx1.highperformance.net (s4.stradamotorsports.com [64.81.163.122]) by mx1.freebsd.org (Postfix) with ESMTP id DBD578FC18 for ; Sun, 12 Jul 2009 22:30:02 +0000 (UTC) (envelope-from jcw@highperformance.net) Received: from [192.168.1.191] ([192.168.1.191]) by mx1.highperformance.net (8.14.3/8.14.3) with ESMTP id n6CMBNIG001974 for ; Sun, 12 Jul 2009 15:11:23 -0700 (PDT) (envelope-from jcw@highperformance.net) Message-ID: <4A5A5F8B.4030909@highperformance.net> Date: Sun, 12 Jul 2009 15:11:23 -0700 From: "Jason C. Wells" User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: chat@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=2.5 tests=ALL_TRUSTED autolearn=failed version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on s4.stradamotorsports.com Cc: Subject: Whitelist Before Execution X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jul 2009 22:30:03 -0000 Is there a method by which we can check the consistency of an executable or library prior to trusting it for execution? For example, if the file doesn't exist in the list of trusted files or the checksums do not match then do not allow execution and write a warning message to the log. I could do this manually with existing features like mtree. It would be nice if the system could do it for me. Later, Jason From owner-freebsd-chat@FreeBSD.ORG Mon Jul 13 15:32:37 2009 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 821A01065674 for ; Mon, 13 Jul 2009 15:32:37 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 54E298FC1E for ; Mon, 13 Jul 2009 15:32:37 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 01E3F46B39; Mon, 13 Jul 2009 11:32:37 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id CF07B8A096; Mon, 13 Jul 2009 11:32:35 -0400 (EDT) From: John Baldwin To: freebsd-chat@freebsd.org Date: Mon, 13 Jul 2009 08:40:30 -0400 User-Agent: KMail/1.9.7 References: <4A5A5F8B.4030909@highperformance.net> In-Reply-To: <4A5A5F8B.4030909@highperformance.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907130840.30499.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 13 Jul 2009 11:32:36 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: "Jason C. Wells" Subject: Re: Whitelist Before Execution X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2009 15:32:37 -0000 On Sunday 12 July 2009 6:11:23 pm Jason C. Wells wrote: > Is there a method by which we can check the consistency of an executable > or library prior to trusting it for execution? For example, if the file > doesn't exist in the list of trusted files or the checksums do not match > then do not allow execution and write a warning message to the log. I > could do this manually with existing features like mtree. It would be > nice if the system could do it for me. I believe csjp@ has a MAC module to store checksums of trusted executables in the kernel and to fail execve() if the executable is not a known trusted binary. -- John Baldwin From owner-freebsd-chat@FreeBSD.ORG Fri Jul 17 23:18:18 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D62E106566C for ; Fri, 17 Jul 2009 23:18:18 +0000 (UTC) (envelope-from brett@lariat.net) Received: from lariat.net (lariat.net [66.119.58.2]) by mx1.freebsd.org (Postfix) with ESMTP id CD4408FC1B for ; Fri, 17 Jul 2009 23:18:17 +0000 (UTC) (envelope-from brett@lariat.net) Received: from anne-o1dpaayth1.lariat.net (IDENT:ppp1000.lariat.net@lariat.net [66.119.58.2]) by lariat.net (8.9.3/8.9.3) with ESMTP id QAA15292 for ; Fri, 17 Jul 2009 16:57:16 -0600 (MDT) Message-Id: <200907172257.QAA15292@lariat.net> X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Fri, 17 Jul 2009 16:57:12 -0600 To: chat@freebsd.org From: Brett Glass Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Cc: Subject: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2009 23:18:18 -0000 Everyone: I'm teaching some new employees UNIX basics, and just ran into the following text on the sh(1) man page: Short-Circuit List Operators ``&&'' and ``||'' are AND-OR list operators. ``&&'' executes the first command, and then executes the second command if the exit status of the first command is zero. ``||'' is similar, but executes the second com- mand if the exit status of the first command is nonzero. ``&&'' and ``||'' both have the same priority. This is exactly backward. && is a "short circuit AND." It stops right away and doesn't evaluate its second operand if its first operand is 0. Why? Because if one operand of an AND operation is 0, we already know the result: 0. It can't be otherwise. Likewise, || is a "short circuit OR." It stops right away and doesn't evaluate its second operand if the first operand is 1 (or anything nonzero). Why? Because if one operand of an OR operation is nonzero, the result can never be 0. How could this error have persisted in the FreeBSD documentation for so long? --Brett Glass From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 00:33:34 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94351106566B for ; Sat, 18 Jul 2009 00:33:34 +0000 (UTC) (envelope-from reed@reedmedia.net) Received: from c-0500.emailmediator.com (c-0500.emailmediator.com [64.85.162.118]) by mx1.freebsd.org (Postfix) with ESMTP id 722E78FC17 for ; Sat, 18 Jul 2009 00:33:34 +0000 (UTC) (envelope-from reed@reedmedia.net) Received: from pool-173-74-38-198.dllstx.fios.verizon.net ([173.74.38.198] helo=reedmedia.net) by c-0500.emailmediator.com with esmtpa (Exim 4.69) (envelope-from ) id 1MRxOI-0006zJ-Ns; Fri, 17 Jul 2009 20:03:03 -0400 Received: from reed@reedmedia.net by reedmedia.net with local (mailout 0.17) id 19377-1247875384; Fri, 17 Jul 2009 19:03:05 -0500 Date: Fri, 17 Jul 2009 19:03:04 -0500 (CDT) From: "Jeremy C. Reed" To: Brett Glass In-Reply-To: <200907172257.QAA15292@lariat.net> Message-ID: References: <200907172257.QAA15292@lariat.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: chat@freebsd.org Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 00:33:34 -0000 The only problem to me is that it says "AND-OR" since they are not C-style logical operators. It should just say "conditional execution". From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 00:38:43 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B5D23106564A for ; Sat, 18 Jul 2009 00:38:43 +0000 (UTC) (envelope-from aw1@stade.co.uk) Received: from v-smtp-auth-relay-1.gradwell.net (v-smtp-auth-relay-1.gradwell.net [79.135.125.40]) by mx1.freebsd.org (Postfix) with ESMTP id 1FB808FC14 for ; Sat, 18 Jul 2009 00:38:42 +0000 (UTC) (envelope-from aw1@stade.co.uk) Received: from 93-97-22-18.zone5.bethere.co.uk ([93.97.22.18] helo=access2.hanley.stade.co.uk) by v-smtp-auth-relay-1.gradwell.net with esmtp (Gradwell gwh-smtpd 1.290) id 4a6110cd.1bbf.7 for chat@freebsd.org; Sat, 18 Jul 2009 01:01:17 +0100 (envelope-sender ) Received: from steerpike.hanley.stade.co.uk (steerpike [192.168.1.10]) by access2.hanley.stade.co.uk (8.14.1/8.14.1) with ESMTP id n6I01G9G014765 for ; Sat, 18 Jul 2009 01:01:16 +0100 (BST) (envelope-from aw1@steerpike.hanley.stade.co.uk) Received: from steerpike.hanley.stade.co.uk (localhost [127.0.0.1]) by steerpike.hanley.stade.co.uk (8.14.3/8.14.3) with ESMTP id n6I01Ggg008740 for ; Sat, 18 Jul 2009 01:01:16 +0100 (BST) (envelope-from aw1@steerpike.hanley.stade.co.uk) Received: (from aw1@localhost) by steerpike.hanley.stade.co.uk (8.14.3/8.14.3/Submit) id n6I01Ght008739 for chat@freebsd.org; Sat, 18 Jul 2009 01:01:16 +0100 (BST) (envelope-from aw1) Date: Sat, 18 Jul 2009 01:01:16 +0100 From: Adrian Wontroba To: chat@freebsd.org Message-ID: <20090718000116.GA8379@steerpike.hanley.stade.co.uk> Mail-Followup-To: Adrian Wontroba , chat@freebsd.org References: <200907172257.QAA15292@lariat.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907172257.QAA15292@lariat.net> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-PRERELEASE Organization: Oh dear, I've joined one again. X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on steerpike.hanley.stade.co.uk X-Virus-Status: Clean Cc: Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: aw1@stade.co.uk List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 00:38:43 -0000 On Fri, Jul 17, 2009 at 04:57:12PM -0600, Brett Glass wrote: > Short-Circuit List Operators > ``&&'' and ``||'' are AND-OR list operators. ``&&'' executes the first > command, and then executes the second command if the exit status of the > first command is zero. ``||'' is similar, but executes the second com- > mand if the exit status of the first command is nonzero. ``&&'' and > ``||'' both have the same priority. > > This is exactly backward. No it is succinctly correct but confusing (the UNIX way?). These operators work on exit codes where 0 = success = true and and !0 = failure = false. [aw1@steerpike ~]$ sh $ true && echo true true $ false || echo false false $ true; echo $? 0 $ false; echo $? 1 $ exit -- Adrian Wontroba Confused? You will be. Just watch ... From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 01:21:30 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6BCAC1065673 for ; Sat, 18 Jul 2009 01:21:30 +0000 (UTC) (envelope-from brett@lariat.net) Received: from lariat.net (lariat.net [66.119.58.2]) by mx1.freebsd.org (Postfix) with ESMTP id 01C238FC1A for ; Sat, 18 Jul 2009 01:21:29 +0000 (UTC) (envelope-from brett@lariat.net) Received: from anne-o1dpaayth1.lariat.net (IDENT:ppp1000.lariat.net@lariat.net [66.119.58.2]) by lariat.net (8.9.3/8.9.3) with ESMTP id TAA16416; Fri, 17 Jul 2009 19:21:19 -0600 (MDT) Message-Id: <200907180121.TAA16416@lariat.net> X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Fri, 17 Jul 2009 19:21:14 -0600 To: aw1@stade.co.uk, chat@freebsd.org From: Brett Glass In-Reply-To: <20090718000116.GA8379@steerpike.hanley.stade.co.uk> References: <200907172257.QAA15292@lariat.net> <20090718000116.GA8379@steerpike.hanley.stade.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Cc: Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 01:21:30 -0000 At 06:01 PM 7/17/2009, Adrian Wontroba wrote: >No it is succinctly correct but confusing (the UNIX way?). These >operators work on exit codes where 0 = success = true and and !0 = >failure = false. As I understand it, when it comes to UNIX result codes, 0 doesn't really mean "true" -- it means "no error." (In other words, it means "false.") Whereas any nonzero value means there was an error (and indicates what kind). In other words, it means that it's "true" that there was an error. So, the semantics of the operators are supposed to be that "false" is "true?" Aaargh! No wonder I don't use short circuit operators much. When zero equals one, it gets rather confusing. It's also confusing that they are called "AND" and "OR" operators (and look like the short-circuit AND and OR operators in other languages, which all do what you would expect). --Brett From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 02:48:39 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F0A5106566C for ; Sat, 18 Jul 2009 02:48:39 +0000 (UTC) (envelope-from aw1@stade.co.uk) Received: from v-smtp-auth-relay-2.gradwell.net (v-smtp-auth-relay-2.gradwell.net [79.135.125.41]) by mx1.freebsd.org (Postfix) with ESMTP id A90F18FC12 for ; Sat, 18 Jul 2009 02:48:38 +0000 (UTC) (envelope-from aw1@stade.co.uk) Received: from 93-97-22-18.zone5.bethere.co.uk ([93.97.22.18] helo=access2.hanley.stade.co.uk) by v-smtp-auth-relay-2.gradwell.net with esmtp (Gradwell gwh-smtpd 1.290) id 4a613804.5514.39; Sat, 18 Jul 2009 03:48:36 +0100 (envelope-sender ) Received: from steerpike.hanley.stade.co.uk (steerpike [192.168.1.10]) by access2.hanley.stade.co.uk (8.14.1/8.14.1) with ESMTP id n6I2masL015865; Sat, 18 Jul 2009 03:48:36 +0100 (BST) (envelope-from aw1@steerpike.hanley.stade.co.uk) Received: from steerpike.hanley.stade.co.uk (localhost [127.0.0.1]) by steerpike.hanley.stade.co.uk (8.14.3/8.14.3) with ESMTP id n6I2maAK010507; Sat, 18 Jul 2009 03:48:36 +0100 (BST) (envelope-from aw1@steerpike.hanley.stade.co.uk) Received: (from aw1@localhost) by steerpike.hanley.stade.co.uk (8.14.3/8.14.3/Submit) id n6I2mZZE010506; Sat, 18 Jul 2009 03:48:35 +0100 (BST) (envelope-from aw1) Date: Sat, 18 Jul 2009 03:48:35 +0100 From: Adrian Wontroba To: Brett Glass Message-ID: <20090718024835.GB8379@steerpike.hanley.stade.co.uk> Mail-Followup-To: Adrian Wontroba , Brett Glass , chat@freebsd.org References: <200907172257.QAA15292@lariat.net> <20090718000116.GA8379@steerpike.hanley.stade.co.uk> <200907180121.TAA16416@lariat.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907180121.TAA16416@lariat.net> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-PRERELEASE Organization: Oh dear, I've joined one again. X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on steerpike.hanley.stade.co.uk X-Virus-Status: Clean Cc: chat@freebsd.org Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: aw1@stade.co.uk List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 02:48:39 -0000 On Fri, Jul 17, 2009 at 07:21:14PM -0600, Brett Glass wrote: > At 06:01 PM 7/17/2009, Adrian Wontroba wrote: > >No it is succinctly correct but confusing (the UNIX way?). These > >operators work on exit codes where 0 = success = true and and !0 = > >failure = false. > As I understand it, when it comes to UNIX result codes, 0 doesn't > really mean "true" -- it means "no error." (In other words, it > means "false.") Whereas any nonzero value means there was an error > (and indicates what kind). In other words, it means that it's > "true" that there was an error. > So, the semantics of the operators are supposed to be that "false" > is "true?" Aaargh! I think mentioning true and false confuses (even more). In this context 0 is success, anything else is failure. That said, the sh man page earlier refutes your 0 means false with: Each command has an exit status that can influence the behavior of other shell commands. The paradigm is that a command exits with zero for nor- mal or success, and non-zero for failure, error, or a false indication. ^^^^^^^^ ^^^^^ > No wonder I don't use short circuit operators much. When zero > equals one, it gets rather confusing. I agree that they can be confusing. Forget the 0 and 1, just think of success and failure. > It's also confusing that they are called "AND" and "OR" operators I agree with that too. As Jeremy wrote, "conditional execution" would have been a better description. > (and look like the short-circuit AND and OR operators in other > languages, which all do what you would expect). Well, they are operators and there are only a limited number of special characters available. Look at all the different uses of & and | in the shell (8-( Perhaps the syntax could have been " and " / " or " (as in Perl's and / or statement qualifiers (something() or die "oops";), but it is far too late to change sh syntax. We have to live with it or use a different shell or language. Far too often do I make the mistake of thinking that something can easily be written using sh, getting deep into it and then wishing I'd used perl instead. Yes, it is amazing what an expert can do with sh, but developing and debugging a complex sh script can take far too long. -- Adrian Wontroba Nearly every complex solution to a programming problem that I have looked at carefully has turned out to be wrong. -- Brent Welch (First cookie out of the box, and almost appropriate.) From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 12:06:22 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F8A61065687; Sat, 18 Jul 2009 12:06:22 +0000 (UTC) (envelope-from fb-chat@psconsult.nl) Received: from mx1.psconsult.nl (psc11.adsl.iaf.nl [80.89.238.138]) by mx1.freebsd.org (Postfix) with ESMTP id C12248FC2D; Sat, 18 Jul 2009 12:06:21 +0000 (UTC) (envelope-from fb-chat@psconsult.nl) Received: from mx1.psconsult.nl (localhost [80.89.238.138]) by mx1.psconsult.nl (8.14.2/8.14.2) with ESMTP id n6IBs6G7002947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 18 Jul 2009 13:54:11 +0200 (CEST) (envelope-from fb-chat@psconsult.nl) Received: (from paul@localhost) by mx1.psconsult.nl (8.14.2/8.14.2/Submit) id n6IBNuws002271; Sat, 18 Jul 2009 13:23:56 +0200 (CEST) (envelope-from fb-chat@psconsult.nl) Date: Sat, 18 Jul 2009 13:23:56 +0200 From: Paul Schenkeveld To: freebsd-chat@freebsd.org, chat@freebsd.org Message-ID: <20090718112355.GA99793@psconsult.nl> Mail-Followup-To: freebsd-chat@freebsd.org, chat@freebsd.org, Adrian Wontroba , Brett Glass References: <200907172257.QAA15292@lariat.net> <20090718000116.GA8379@steerpike.hanley.stade.co.uk> <200907180121.TAA16416@lariat.net> <20090718024835.GB8379@steerpike.hanley.stade.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090718024835.GB8379@steerpike.hanley.stade.co.uk> User-Agent: Mutt/1.5.17 (2007-11-01) Cc: Brett Glass Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 12:06:26 -0000 On Sat, Jul 18, 2009 at 03:48:35AM +0100, Adrian Wontroba wrote: > > No wonder I don't use short circuit operators much. When zero > > equals one, it gets rather confusing. > > I agree that they can be confusing. Forget the 0 and 1, just think of > success and failure. > > > It's also confusing that they are called "AND" and "OR" operators > > I agree with that too. As Jeremy wrote, "conditional execution" would > have been a better description. Their naming and meaning are completely in line with the semantics of the if, while and until operators of sh. For example: if newfs /dev/da0 && mount /dev/da0 /mnt && mkdir /mnt/some_dir then cp this_file /mnt/some_dir chown 123:456 /mnt/some_dir chmod u=rw,go=r /mnt/some_dir echo "Installed this_file in /mnt/some_dir" fi Meaning: *IF* I can newfs my usb stick *AND* I can mount it on /mnt *AND* making a subdirectory on it succeeds *THEN* copy this_file into that directory and so on. Remind that if, while and until, although often followed by the [ synonym of the test(1) command, the original intent of them is that they can be followed by any command and operatoe on the success/failure condition of that command. Choosing 0 for true and non-zero for false is also a very natural choice. There is only one way the command can succeed and many ways the command can fail. So if you have to choose one value from the range 0 through 255 to use for success I'd go for 42^W 0 of course! > > (and look like the short-circuit AND and OR operators in other > > languages, which all do what you would expect). > > Well, they are operators and there are only a limited number of special > characters available. Look at all the different uses of & and | in the > shell (8-( > > Perhaps the syntax could have been " and " / " or " (as in Perl's > and / or statement qualifiers (something() or die "oops";), but it is > far too late to change sh syntax. We have to live with it or use a > different shell or language. How would they then be distinguishable from file names on the same command line? > Far too often do I make the mistake of thinking that something can > easily be written using sh, getting deep into it and then wishing I'd > used perl instead. Yes, it is amazing what an expert can do with sh, but > developing and debugging a complex sh script can take far too long. That brings us back to the original cultural decision made in UNIX, there is not one command language, compiler, text formatter or whatever which is tied to the system (or built-in) but you can choose whichever suits your needs best or you can write your own if you like none of them. I do occasionally use perl (once every few years) but I can fully express myself using sh(1) and derived shells (ksh, bash, zsh). Looking at the footprint of the shells and perl and knowing that every UN*X-like system I've used since 1983 has some shell which is sh(1) compatible (at least for 95%) and perl comes in versions (porting from perl 4.036 to perl 5 cost me a lot of time ten years ago), needs tons of modules (if you pick perl scripts from the Internet) and is not part of the base system of FreeBSD (and many other UN*X systems), for me sh(1) is the natural choice but please choose your own favorite as that's what the UN*X culture explicitely promotes. My $.02 Paul Schenkeveld From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 12:06:22 2009 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F8A61065687; Sat, 18 Jul 2009 12:06:22 +0000 (UTC) (envelope-from fb-chat@psconsult.nl) Received: from mx1.psconsult.nl (psc11.adsl.iaf.nl [80.89.238.138]) by mx1.freebsd.org (Postfix) with ESMTP id C12248FC2D; Sat, 18 Jul 2009 12:06:21 +0000 (UTC) (envelope-from fb-chat@psconsult.nl) Received: from mx1.psconsult.nl (localhost [80.89.238.138]) by mx1.psconsult.nl (8.14.2/8.14.2) with ESMTP id n6IBs6G7002947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 18 Jul 2009 13:54:11 +0200 (CEST) (envelope-from fb-chat@psconsult.nl) Received: (from paul@localhost) by mx1.psconsult.nl (8.14.2/8.14.2/Submit) id n6IBNuws002271; Sat, 18 Jul 2009 13:23:56 +0200 (CEST) (envelope-from fb-chat@psconsult.nl) Date: Sat, 18 Jul 2009 13:23:56 +0200 From: Paul Schenkeveld To: freebsd-chat@freebsd.org, chat@freebsd.org Message-ID: <20090718112355.GA99793@psconsult.nl> Mail-Followup-To: freebsd-chat@freebsd.org, chat@freebsd.org, Adrian Wontroba , Brett Glass References: <200907172257.QAA15292@lariat.net> <20090718000116.GA8379@steerpike.hanley.stade.co.uk> <200907180121.TAA16416@lariat.net> <20090718024835.GB8379@steerpike.hanley.stade.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090718024835.GB8379@steerpike.hanley.stade.co.uk> User-Agent: Mutt/1.5.17 (2007-11-01) Cc: Brett Glass Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 12:06:27 -0000 On Sat, Jul 18, 2009 at 03:48:35AM +0100, Adrian Wontroba wrote: > > No wonder I don't use short circuit operators much. When zero > > equals one, it gets rather confusing. > > I agree that they can be confusing. Forget the 0 and 1, just think of > success and failure. > > > It's also confusing that they are called "AND" and "OR" operators > > I agree with that too. As Jeremy wrote, "conditional execution" would > have been a better description. Their naming and meaning are completely in line with the semantics of the if, while and until operators of sh. For example: if newfs /dev/da0 && mount /dev/da0 /mnt && mkdir /mnt/some_dir then cp this_file /mnt/some_dir chown 123:456 /mnt/some_dir chmod u=rw,go=r /mnt/some_dir echo "Installed this_file in /mnt/some_dir" fi Meaning: *IF* I can newfs my usb stick *AND* I can mount it on /mnt *AND* making a subdirectory on it succeeds *THEN* copy this_file into that directory and so on. Remind that if, while and until, although often followed by the [ synonym of the test(1) command, the original intent of them is that they can be followed by any command and operatoe on the success/failure condition of that command. Choosing 0 for true and non-zero for false is also a very natural choice. There is only one way the command can succeed and many ways the command can fail. So if you have to choose one value from the range 0 through 255 to use for success I'd go for 42^W 0 of course! > > (and look like the short-circuit AND and OR operators in other > > languages, which all do what you would expect). > > Well, they are operators and there are only a limited number of special > characters available. Look at all the different uses of & and | in the > shell (8-( > > Perhaps the syntax could have been " and " / " or " (as in Perl's > and / or statement qualifiers (something() or die "oops";), but it is > far too late to change sh syntax. We have to live with it or use a > different shell or language. How would they then be distinguishable from file names on the same command line? > Far too often do I make the mistake of thinking that something can > easily be written using sh, getting deep into it and then wishing I'd > used perl instead. Yes, it is amazing what an expert can do with sh, but > developing and debugging a complex sh script can take far too long. That brings us back to the original cultural decision made in UNIX, there is not one command language, compiler, text formatter or whatever which is tied to the system (or built-in) but you can choose whichever suits your needs best or you can write your own if you like none of them. I do occasionally use perl (once every few years) but I can fully express myself using sh(1) and derived shells (ksh, bash, zsh). Looking at the footprint of the shells and perl and knowing that every UN*X-like system I've used since 1983 has some shell which is sh(1) compatible (at least for 95%) and perl comes in versions (porting from perl 4.036 to perl 5 cost me a lot of time ten years ago), needs tons of modules (if you pick perl scripts from the Internet) and is not part of the base system of FreeBSD (and many other UN*X systems), for me sh(1) is the natural choice but please choose your own favorite as that's what the UN*X culture explicitely promotes. My $.02 Paul Schenkeveld From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 16:39:53 2009 Return-Path: Delivered-To: freebsd-chat@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65C21106564A for ; Sat, 18 Jul 2009 16:39:53 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id E0AB28FC1A for ; Sat, 18 Jul 2009 16:39:52 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id n6IGdZG0015653; Sat, 18 Jul 2009 18:39:50 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id n6IGdZxG015652; Sat, 18 Jul 2009 18:39:35 +0200 (CEST) (envelope-from olli) Date: Sat, 18 Jul 2009 18:39:35 +0200 (CEST) Message-Id: <200907181639.n6IGdZxG015652@lurza.secnetix.de> From: Oliver Fromme To: freebsd-chat@FreeBSD.ORG In-Reply-To: <200907172257.QAA15292@lariat.net> X-Newsgroups: list.freebsd-chat User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Sat, 18 Jul 2009 18:39:51 +0200 (CEST) Cc: Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-chat@FreeBSD.ORG List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 16:39:53 -0000 Actually I've never regarded "&&" and "||" (and also "|" and "&") as operators, like real operators in a programming language, but as command separators, much like ";", but with special semantics. Note that foo && bar && baz foo || bar || baz is the same as if foo; then if bar; then baz; fi; fi if ! foo; then if ! bar; then baz; fi; fi Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "If you aim the gun at your foot and pull the trigger, it's UNIX's job to ensure reliable delivery of the bullet to where you aimed the gun (in this case, Mr. Foot)." -- Terry Lambert, FreeBSD-hackers mailing list. From owner-freebsd-chat@FreeBSD.ORG Sat Jul 18 17:23:05 2009 Return-Path: Delivered-To: chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 572CD106566B for ; Sat, 18 Jul 2009 17:23:05 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id 19C618FC0A for ; Sat, 18 Jul 2009 17:23:05 +0000 (UTC) (envelope-from des@des.no) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 96BF26D418; Sat, 18 Jul 2009 19:03:39 +0200 (CEST) Received: by ds4.des.no (Postfix, from userid 1001) id 76B0F844B5; Sat, 18 Jul 2009 19:03:39 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Adrian Wontroba References: <200907172257.QAA15292@lariat.net> <20090718000116.GA8379@steerpike.hanley.stade.co.uk> <200907180121.TAA16416@lariat.net> <20090718024835.GB8379@steerpike.hanley.stade.co.uk> Date: Sat, 18 Jul 2009 19:03:39 +0200 In-Reply-To: <20090718024835.GB8379@steerpike.hanley.stade.co.uk> (Adrian Wontroba's message of "Sat, 18 Jul 2009 03:48:35 +0100") Message-ID: <867hy5sz2s.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Brett Glass , chat@freebsd.org Subject: Re: Bourne shell short-circuit operators improperly documented X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 17:23:05 -0000 Adrian Wontroba writes: > Perhaps the syntax could have been " and " / " or " (as in Perl's > and / or statement qualifiers (something() or die "oops";), but it is > far too late to change sh syntax. We have to live with it or use a > different shell or language. Pop quiz: what are the semantics of the follwing command line after your proposed change: echo I need a box and cat litter for my new kittens. There is absolutely nothing surprising or illogical about the && and || command separators. There is absolutely nothing surprising about "zero means success, non- zero means failure" either - that's how most Unix system calls and many standard C library functions work. I'm sure we all have better things to do than argue about this non- issue. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no