]> git.ipfire.org Git - thirdparty/bash.git/blob - examples/functions/emptydir
412af5b13085da3deaab7301147a4ace0b3ac1eb
[thirdparty/bash.git] / examples / functions / emptydir
1 #! /bin/bash
2 #
3 #Derived from:
4 #
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>
10
11 # usage: emptydir [dirname] ; default dirname is "."
12
13 emptydir()
14 {
15 typeset file dir=${1:-.}
16 [[ -d $dir ]] || {
17 echo "$FUNCNAME: $dir is not a directory" >&2
18 return 2
19 }
20 for file in $dir/.* $dir/*
21 do
22 case ${file#$dir/} in
23 .|..) ;;
24 \*) [[ -e $file ]];let $?;return;;
25 *) return 1;;
26 esac
27 done
28 }