[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to test for empty dir?
From: |
Chris F.A. Johnson |
Subject: |
Re: best way to test for empty dir? |
Date: |
Thu, 10 Dec 2009 16:42:29 -0500 (EST) |
User-agent: |
Alpine 2.00 (LMD 1167 2008-08-23) |
On Thu, 10 Dec 2009, Marc Herbert wrote:
> 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!
is_file()
{
for f
do
[ -f "$f" ] && return
done
return 1
}
is_file /path/to/dir/* || echo empty
--
Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
- best way to test for empty dir?, Marc Herbert, 2009/12/10
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/10
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/10
- Re: best way to test for empty dir?,
Chris F.A. Johnson <=
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/11
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/11
- Re: best way to test for empty dir?, Sven Mascheck, 2009/12/11
- Re: best way to test for empty dir?, Chris F.A. Johnson, 2009/12/11
- Re: best way to test for empty dir?, Sven Mascheck, 2009/12/11
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/11
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/11
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/11