[ALUG] Re: How to check a directory is empty (probably in bash)?
Eur Ing Chris Green
cl at isbd.net
Wed Feb 21 13:08:34 GMT 2007
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.
Backticks are still more 'universal', for example backticks work
in mutt's configuration file.
--
Chris Green
More information about the main
mailing list