[ALUG] Re: Re: How to check a directory is empty (probably in bash)?
Eur Ing Chris Green
cl at isbd.net
Wed Feb 21 13:48:40 GMT 2007
On Wed, Feb 21, 2007 at 01:16:51PM +0000, Brett Parker wrote:
> On Wed, Feb 21, 2007 at 01:08:34PM +0000, Eur Ing Chris Green wrote:
> > On Wed, Feb 21, 2007 at 12:54:35PM +0000, Brett Parker wrote:
> > > On Wed, Feb 21, 2007 at 12:49:13PM +0000, Paul wrote:
> > > > On Wednesday 21 February 2007 11:42, Eur Ing Chris Green wrote:
> > > > > What's the simplest (and/or most concise) way to check for an empty
> > > > > directory?
> > > >
> > > > if test -z `ls foo` ; then wibble ; fi
> > > >
> > > > Or
> > > >
> > > > if [ -z `ls foo` ] ; then wibble ; fi
> > > >
> > > > There's probably other ways....
> > >
> > > Just a quick note - in bash, and any real posix shell, it's (generally)
> > > better form to use $(command) than `command`, it's more readable and is
> > > nestable if needed...
> > >
> > > Mr Pashley has a few things to say about backticks, it's worth a quick
> > > read if nothing else:
> > > http://www.davidpashley.com/blog/programming/shell/backticks.html
> > >
> > Very true (the comments above backticks that is), however:-
> >
> > At work my development machine is a Solaris system where (on the
> > default shell at least) the $(command) syntax doesn't work. I
> > use a lot of the scripts I develop both at home and at work.
>
> Yeah - but Solaris' /bin/sh isn't POSIX compliant, it's a broken evil
> thing - I'm fairly sure that they haven't bothered to fix it yet because
> a lot of people worked round the fact that solaris had a broken /bin/sh
> by default and so wrote around the broken shell.
>
I quite agree, but that doesn't change the fact that I have to develop
and maintain code on Solaris.
--
Chris Green
More information about the main
mailing list