Bash problems?
Tomas Larsson
tomas at tlec.se
Tue Jun 27 11:56:56 UTC 2006
> -----Original Message-----
> From: fedora-list-bounces at redhat.com
> [mailto:fedora-list-bounces at redhat.com] On Behalf Of Ben Stringer
> Sent: Tuesday, June 27, 2006 1:43 PM
> To: For users of Fedora Core releases
> Subject: RE: Bash problems?
>
> On Tue, 2006-06-27 at 13:23 +0200, Tomas Larsson wrote:
> > > -----Original Message-----
> > > From: fedora-list-bounces at redhat.com
> > > [mailto:fedora-list-bounces at redhat.com] On Behalf Of Paul Howarth
> > > Sent: Tuesday, June 27, 2006 12:34 PM
> > > To: For users of Fedora Core releases
> > > Subject: Re: Bash problems?
> > >
> > > Ben Stringer wrote:
> > > > On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
> > > >> Dear group.
> > > >> How do I do to, within a scrip, check if a directory I
> > > empty or not.
> > > >> Cant find a way to do this in a simple way.
> > > >
> > > > DIR_CONTENTS=`ls $DIR`
> > > > if [ "$DIR_CONTENTS" == "" ]
> > > > then
> > > > echo "$DIR is empty"
> > > > else
> > > > echo "$DIR contains:"
> > > > echo $DIR_CONTENTS
> > > > fi
> > >
> > > I'd use "ls -A $DIR" there rather than "ls $DIR" so as to
> spot files
> > > with names starting with a dot.
>
> Yes - nice improvement Paul.
>
> > >
> > > Paul.
> > Thanks all, however for some reason 'ls $DIR' didn't work.
> > $(ls $DIR) did the job.
>
> You had the ticks the wrong way. But using the round brackets
> is equivalent.
>
> >
> > Now, I want to exlude sub-dirs in the ls command?
>
> Look at using the "find" command with the option -maxdepth 1
>
> Eg.
>
> DIR_CONTENTS=$( find $DIR -maxdepth 1 -type f )
>
> Note that this will _only_ find files, not symlinks,
> block/char special files, sockets etc. See the find manpage
> for details on "-type f".
>
> Cheers, Ben
>
> >
> > With best regards
> >
> > Tomas Larsson
> > Sweden
> >
> > Verus Amicus Est Tamquam Alter Idem
> >
Thanks, seems to do the job.
With best regards
Tomas Larsson
Sweden
Verus Amicus Est Tamquam Alter Idem
More information about the fedora-list
mailing list