Received: from spf1.us4.outblaze.com (spf1.us4.outblaze.com [205.158.62.23]) by sdf.lonestar.org (8.12.10/8.12.10) with ESMTP id iACL2gjs018394 for ; Fri, 12 Nov 2004 21:02:42 GMT Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by spf1.us4.outblaze.com (Postfix) with ESMTP id 44D7153C55 for ; Fri, 12 Nov 2004 21:02:40 +0000 (GMT) Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CSihf-0007fr-Fd for migo@homemail.com; Fri, 12 Nov 2004 16:11:31 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CSihL-0007fk-Qf for gnu-arch-users@gnu.org; Fri, 12 Nov 2004 16:11:11 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CSihL-0007fR-6J for gnu-arch-users@gnu.org; Fri, 12 Nov 2004 16:11:11 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CSihL-0007fH-38 for gnu-arch-users@gnu.org; Fri, 12 Nov 2004 16:11:11 -0500 Received: from [144.140.71.11] (helo=gizmo01ps.bigpond.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1CSiYd-0007Ph-U6 for gnu-arch-users@gnu.org; Fri, 12 Nov 2004 16:02:12 -0500 Received: (qmail 15485 invoked from network); 12 Nov 2004 21:02:09 -0000 Received: from unknown (HELO psmam11.bigpond.com) (144.135.25.100) by gizmo01ps.bigpond.com with SMTP; 12 Nov 2004 21:02:09 -0000 Received: from cpe-144-132-221-212.nsw.bigpond.net.au ([144.132.221.212]) by psmam11.bigpond.com(MAM REL_3_4_2a 225/4661928) with SMTP id 4661928; Sat, 13 Nov 2004 07:02:09 +1000 Received: by poolcompsonline.com (Postfix, from userid 1000) id 70C69783E7; Sat, 13 Nov 2004 08:04:57 +1100 Subject: Re: [Gnu-arch-users] bash scripting conditionals: "-a" vs "-e" From: Zenaan Harkness To: Jan Hudec In-Reply-To: <20041112104128.GC721@vagabond> References: <1100222699.3031.43.camel@localhost.localdomain> <20041112104128.GC721@vagabond> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1100293497.3074.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Sat, 13 Nov 2004 08:04:57 +1100 Cc: arch , Matthias Klose X-BeenThere: gnu-arch-users@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: a discussion list for all things arch-ish List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: gnu-arch-users-bounces+migo=homemail.com@gnu.org Errors-To: gnu-arch-users-bounces+migo=homemail.com@gnu.org Status: RO Content-Length: 2331 Lines: 73 Matthias, can you confirm if this is a doco bug? On Fri, 2004-11-12 at 21:41, Jan Hudec wrote: > On Fri, Nov 12, 2004 at 12:24:59 +1100, Zenaan Harkness wrote: > > Is -a historical - or why is it there? > > It's the "and" operator. > > > I converted a bunch of -f to -a in my build scripts, because I realised > > I didn't want to distinguish between sylinks and 'regular' files. > > You mean -e, not -a, right? -e is existence test without restriction on > entry type... Well that seems to be the functionality, but the docs tell otherwise, both info and man include the following: ... -a file True if file exists. -b file True if file exists and is a block special file. -c file True if file exists and is a character special file. -d file True if file exists and is a directory. -e file True if file exists. -f file True if file exists and is a regular file. ... Of course, they both also include documentation about -a being &&. My suspicion is that -a might be unary-file-test (can't add ! to negate the condition for example)?? but I haven't tested this... it could just be a doco bug. > > Then I discovered that this broke when inside the construction > > "[ ! -a file ]" since the -a becomes like &&. > > Because -a IS and. [ \! -a $file ] is false by definition (I'd think > it's an error, but it is just always false). > > > So I went reading again and found out that -e appears the same as -a, > > and -a is like &&. > > No, -e is NOT the same as -a. -e is what you want. -a is not. See doco cut and paste above... > -a is not quite like &&. That is: > [ expr1 -a expr2 ] > [ expr1 ] && [ expr2 ] > are equivalent, except the former is faster (just one test invocation), > but only the second has shortcut evaluation (expr2 is not evaluated if > expr1 is false). > > > So why -a at all? > > Because you need an and operator sometimes. > > ------------------------------------------------------------------------------- > Jan 'Bulb' Hudec _______________________________________________ Gnu-arch-users mailing list Gnu-arch-users@gnu.org http://lists.gnu.org/mailman/listinfo/gnu-arch-users GNU arch home page: http://savannah.gnu.org/projects/gnu-arch/