From owner-freebsd-questions Tue May 29 21: 8:54 2001 Delivered-To: freebsd-questions@freebsd.org Received: from smtp2.cybersurf.net (smtp2.cybersurf.net [209.197.145.112]) by hub.freebsd.org (Postfix) with ESMTP id 30BE737B43C for ; Tue, 29 May 2001 21:08:50 -0700 (PDT) (envelope-from 01031149@3web.net) Received: from 3web.net ([209.197.156.113]) by smtp2.cybersurf.net (Netscape Messaging Server 4.15) with SMTP id GE4RIN00.RX6 for ; Tue, 29 May 2001 22:08:47 -0600 Received: by 3web.net (EzMTS MTSAgent 1.22b Service) ; Tue, 29 May 01 22:08:13 -0600 for Received: from 3web.net (10.0.0.2) by 3web.net (EzMTS MTSSmtp 1.50 Service) ; Mon, 28 May 01 14:54:57 -0600 for Received: by mandy.rockingd.calgary.ab.ca (sSMTP sendmail emulation); Mon, 28 May 2001 14:54:32 -0600 Date: Mon, 28 May 2001 14:54:31 -0600 From: Duke Normandin <01031149@3web.net> To: Freebsd Questions Subject: Re: Need help with Bash function Message-ID: <20010528145430.A93259@mandy.rockingd.calgary.ab.ca> Mail-Followup-To: Freebsd Questions References: <93022994@toto.iv> <15122.25713.306089.220192@guru.mired.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <15122.25713.306089.220192@guru.mired.org>; from "Mike Meyer" on Mon, May 28, 2001 at 09:45:05AM X-Envelope-Receiver: 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 On Mon, May 28, 2001 at 09:45:05AM -0500, Mike Meyer wrote: > Duke Normandin <01031149@3web.net> types: > > I'm trying to debug the following function w/o much success. > > > > function ezq() { > > if [ -a ~/tmp/* ]; then > > echo -e "there's something here....\n" > > else > > echo -e "empty....\n" > > fi > > } > > I keep on getting: > > > > '[: binary operator expected' > > > > Is it whinning about the '-a' above? Why? > > Because -a is a binary operator. It's format is "expresion1 -a expression2", > though the message you're getting is strange. I get a different one. I see! "binary" as in 2 expressions required. As opposed to "unary" - one expression required. > > All I want to do is to check to see if a directory is empty or not. > > TIA... > > That's a bit trickier; test - aka '[' - doesn't have any primitives > for looking at directories, or arrays of any kind. So you need to > generate a list of files in a string - which test can look at - and > then check to see if the string is empty or not. The following works > for me: > > function ezq() { > if [ -n "`ls ~/tmp`" ]; then > echo "there's something here...." > else > echo empty... > fi > } > >