From owner-freebsd-questions Mon May 28 9: 0:32 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mail5.carolina.rr.com (fe5.southeast.rr.com [24.93.67.52]) by hub.freebsd.org (Postfix) with ESMTP id 04D9A37B424 for ; Mon, 28 May 2001 09:00:27 -0700 (PDT) (envelope-from jconner@enterit.com) Received: from CONCON.enterit.com ([66.56.135.129]) by mail5.carolina.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Mon, 28 May 2001 12:00:25 -0400 Message-Id: <5.1.0.14.0.20010528112740.0239cd68@mail.enterit.com> X-Sender: jconner@enterit.com@mail.enterit.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Mon, 28 May 2001 12:21:31 -0400 To: Mike Meyer From: Jim Conner Subject: Re: Need help with Bash function Cc: Duke Normandin <01031149@3web.net>, questions@freebsd.org In-Reply-To: <15122.25713.306089.220192@guru.mired.org> References: <93022994@toto.iv> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed 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 The only thing you are lacking is quotes in your condition... function ezq() { if [ -a "~/tmp/*" ] then echo -e "there's something here....\n" else echo -e "empty....\n" fi } Now, I ususally use ksh but bash should be able to do the same thing. At 09:45 AM 5/28/2001 -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. > > > 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 >} > > -- >Mike Meyer 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 - Jim - NOTJames - jconner@enterit.com - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - | Today's errors, in contrast: | - | Windows - "Invalid page fault in module kernel32.dll at 0032:A16F2935" | - | UNIX - "segmentation fault - core dumped" | - | Humans - "OOPS, I've fallen and I can't get up" | - -------------------------------------------------------------------------- - (To view this properly use a non-proportional font in your MUA) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message