Re: Simple Scripting ? (Is directory empty?)


Subject: Re: Simple Scripting ? (Is directory empty?)
From: Adam Price (Adam@oldchildrensbooks.com)
Date: Fri Dec 17 1999 - 17:40:49 MST


On Mon, 13 Dec 1999, Guillaume Marçais wrote:
> Try:
> if [ `ls /var/qmail/alias/pppdir/new/ | wc -l` -eq 0 ]
> then
> echo "Directory empty"
> else
> echo "Directory *not* empty"
> fi
>
> Guillaume.
>
No luck. This test always proves true (although wc -l returns 0) and if I
use ne, I get

        /usr/bin/qflush: [: ne: binary operator expected
        No mail to send

It makes me think the ticks are wrong, but I have no idea how to right
them.

        -Adam

> On Mon, 13 Dec 1999, Adam Price wrote:
> >
> > The following script is supposed to do the following:
> >
> > 1. Look at the directory /var/qmail/alias/pppdir/new/
> > 2. If it is nonempty, run the maildirsmtp program to empty it
> > 3. Otherwise say there was no mail to send.
> >
> > Instead, the initial test ALWAYS proves true. This results in lots of
> > "directory was empty messages. I have tried various flags, (-s, -f,
> > -N) none of them work (and from reading the man pages, they shouldn't)
> > I know how I could accomplish this using a temporary file, and cat'ing ls
> > into it, but that seem like overkill.
> >
> > How do I ask bash if a directory is empty?

-- 
adam@oldchildrensbooks.com

People are more violently opposed to fur than leather because it is safer to harrass rich women than motorcycle gangs.



This archive was generated by hypermail 2a24 : Sun Jan 02 2000 - 12:12:58 MST