From 772f20abb0a3a0979c440114bf3a1cff5b3cef03 Mon Sep 17 00:00:00 2001 From: cvpcs Date: Wed, 2 Jun 2010 11:02:31 -0500 Subject: initial import of bash 4.1 --- examples/functions/emptydir | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/functions/emptydir (limited to 'examples/functions/emptydir') diff --git a/examples/functions/emptydir b/examples/functions/emptydir new file mode 100644 index 0000000..412af5b --- /dev/null +++ b/examples/functions/emptydir @@ -0,0 +1,28 @@ +#! /bin/bash +# +#Derived from: +# +#From: damercer@mmm.com (Dan Mercer) +#Newsgroups: comp.unix.admin,comp.unix.shell,comp.unix.programmer,comp.sys.sun.admin +#Subject: Re: Command to find out if a directory is empty +#Date: 17 Aug 2000 14:35:56 GMT +#Message-ID: <8ngt8c$fmr$1@magnum.mmm.com> + +# usage: emptydir [dirname] ; default dirname is "." + +emptydir() +{ + typeset file dir=${1:-.} + [[ -d $dir ]] || { + echo "$FUNCNAME: $dir is not a directory" >&2 + return 2 + } + for file in $dir/.* $dir/* + do + case ${file#$dir/} in + .|..) ;; + \*) [[ -e $file ]];let $?;return;; + *) return 1;; + esac + done +} -- cgit v1.1