Patch-ID: bash40-021
[bash.git] / examples / functions / emptydir
blob412af5b13085da3deaab7301147a4ace0b3ac1eb
1 #! /bin/bash
3 #Derived from:
5 #From: damercer@mmm.com (Dan Mercer)
6 #Newsgroups: comp.unix.admin,comp.unix.shell,comp.unix.programmer,comp.sys.sun.admin
7 #Subject: Re: Command to find out if a directory is empty
8 #Date: 17 Aug 2000 14:35:56 GMT
9 #Message-ID: <8ngt8c$fmr$1@magnum.mmm.com>
11 # usage: emptydir [dirname] ; default dirname is "."
13 emptydir()
15 typeset file dir=${1:-.}
16 [[ -d $dir ]] || {
17 echo "$FUNCNAME: $dir is not a directory" >&2
18 return 2
20 for file in $dir/.* $dir/*
22 case ${file#$dir/} in
23 .|..) ;;
24 \*) [[ -e $file ]];let $?;return;;
25 *) return 1;;
26 esac
27 done