Date: Mon, 28 May 2001 14:54:31 -0600 From: Duke Normandin <01031149@3web.net> To: Freebsd Questions <freebsd-questions@freebsd.org> Subject: Re: Need help with Bash function Message-ID: <20010528145430.A93259@mandy.rockingd.calgary.ab.ca> In-Reply-To: <15122.25713.306089.220192@guru.mired.org>; from "Mike Meyer" on Mon, May 28, 2001 at 09:45:05AM References: <93022994@toto.iv> <15122.25713.306089.220192@guru.mired.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 > } > > <mike Thanks, Mike! Works like a bloody charm. I received another reply with a similar solution, so these are being committed to my "shell scripting" binder. -- -duke Calgary, Alberta, Canada To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010528145430.A93259>