[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checking if directory is empty in postrm



On Mon, Nov 16, 1998 at 12:28:17AM -0600, john@dhh.gt.org wrote:
> Marcus Brinkmann writes:
> >   [ `ls -1 $dir` ]
> > This does not work. If the dir contains no file, it is "[ ]",
> > which returns 0, which is fine. If it contains more than one file, it is too
> > many arguments, therefore returning 1, which is also fine. But if it
> > contains one file, it returns 0, which is wrong.
> 
> Should read:
> 
> [ "`ls -1A $dir`" ]
> 
> This returns '1' if the directory is empty and '0' otherwise.  It is not
> tricked by spaces or other unusual characters in file names.

Ah, I see. Thank you, this is definitely the winner. No pipe, no second
exectuable, great!

It's nice to learn something new everyday,
Marcus

-- 
"Rhubarb is no Egyptian god."        Debian GNU/Linux        finger brinkmd@ 
Marcus Brinkmann                   http://www.debian.org    master.debian.org
Marcus.Brinkmann@ruhr-uni-bochum.de                        for public  PGP Key
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/       PGP Key ID 36E7CD09


Reply to: