On Thu, 10 Dec 2009 17:31:20 +0000
Marc Herbert <[email protected]> wrote:
> Hi,
>
Hello
> Does anyone know a more elegant way to check for file existence?
> Something that does not fork a subshell. And is also more readable
> maybe. And is obviously not much longer.
>
> empty_dir()
> {
> test "x$(echo $1/*$2)" = "x$1"'/*'"$2"
> }
>
>
> Warning: I find neither "noglob" nor "ls" elegant, sorry!
>
Maybe you want the Chris F.A Johnson's implementation [1]:
set -- "/tmp/emptydir"/*
[[ -f $1 ]] && echo non-empty || echo empty;
References:
[1]
http://www.issociate.de/board/goto/866027/checking_if_a_directory_is_empty.html
--
Matias A. Fonzo <[email protected]>