On Wed, Apr 02, 2014 at 07:54:58AM +0300, Pierre Gaston wrote: > On Wed, Apr 2, 2014 at 6:04 AM, Linda Walsh <b...@tlinx.org> wrote: > > Well don't know if it circumvents the /fd/62 prob > > yet (got a few places more to check & convert), > > but this seems to work for checking if a file > > or dir is empty: > > > > function empty { > > [[ $# -lt 1 ]] && return -1 > > [[ -f $1 && ! -s $1 ]] && return 0 > > [[ -d $1 ]] && { > > readarray entries<<<"$(cd "$1" && printf "%s\n" * 2>/dev/null)" > > ((${#entries[@]} < 3)) && return 0 > > } > > return 1 > > }
That's unnecessarily complex. > why not simply: entries=("$1"/*) ? You need to activate nullglob and dotglob first, but yes, that would be the way I'd recommend. That's what we use in http://mywiki.wooledge.org/BashFAQ/004 as well.