From owner-freebsd-questions Mon May 28 7:45:10 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-65-26-235-186.mmcable.com [65.26.235.186]) by hub.freebsd.org (Postfix) with SMTP id D8F1237B423 for ; Mon, 28 May 2001 07:45:05 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 80682 invoked by uid 100); 28 May 2001 14:45:05 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15122.25713.306089.220192@guru.mired.org> Date: Mon, 28 May 2001 09:45:05 -0500 To: Duke Normandin <01031149@3web.net> Cc: questions@freebsd.org Subject: Re: Need help with Bash function In-Reply-To: <93022994@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ 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 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. > 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 } http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message