From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19032 invoked by alias); 7 Mar 2012 08:52:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16853 Received: (qmail 5034 invoked from network); 7 Mar 2012 08:52:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at math.technion.ac.il does not designate permitted sender hosts) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EANogV0+ERHMG/2dsb2JhbABDtQ2BB4F+AQU6Pw4CC0YUBxExE4gHC7oQBJAJYwSVPgGQFoJl X-IronPort-AV: E=Sophos;i="4.73,545,1325455200"; d="scan'208";a="82100521" Date: Wed, 7 Mar 2012 10:52:36 +0200 From: Nadav Har'El To: Peter Stephenson Cc: zsh-users@zsh.org Subject: Re: [[ and [ Message-ID: <20120307085236.GC15125@fermat.math.technion.ac.il> References: <4F52D510.6000002@sergio.spb.ru> <120303202448.ZM21278@torch.brasslantern.com> <4F555B0B.1050401@sergio.spb.ru> <120305220555.ZM27709@torch.brasslantern.com> <4F55EF85.3050809@sergio.spb.ru> <20120306113532.789859ca@pwslap01u.europe.root.pri> <20120306114404.359e1c9d@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120306114404.359e1c9d@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.20 (2009-12-10) On Tue, Mar 06, 2012, Peter Stephenson wrote about "Re: [[ and [": > On Tue, 6 Mar 2012 11:35:32 +0000 > Sigh. Sort of. [ ... -eq ...] and [[ ... -eq ... ]] are numeric tests, > so if foo is a string of zeros it's not doing what it looks like. I > should have said > > [ $foo = "" ]] >... > I don't know why it's that way round, it seems a bit illogical (which is > why Perl is the other way), but it always has been that way. In addition to being the way it's always been, it makes even more sense when you consider the newer features of ksh (and following it, zsh and bash). In ksh, arithmetic expressions got a new syntax, ((. If if you would like to check for arithmetic equality (or whatever), you'd most likely use if (( $foo == 2 )) or even better, without the "$": if (( foo == 2 )) The new (( can of course do much more interesting arithmetic expressions, e.g.: if (( foo+1 < bar/2.0 )) Then, test, [, or [[ remain useful only for *strings*. So it makes sense for their ==, <, etc., to be geared for comparing strings. Ksh even considers "-eq", "-gt" to be obsolete - if you're using them, you should probably be using (( instead. The zsh manual does not state that "-eq" and the rest are obsolete (in Conditional Expressions), but maybe it should: Ksh added this statement to its manual in 1993, after it was absent in 1998: Compare http://www.research.att.com/sw/download/man/man1/ksh88.html http://www.research.att.com/sw/download/man/man1/ksh.html -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |Live as if you were to die tomorrow, http://nadav.harel.org.il |learn as if you were to live forever.