[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] test: Add unary operator -E: test that a file is an empty di
From: |
Assaf Gordon |
Subject: |
Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory |
Date: |
Wed, 6 Apr 2016 15:36:29 -0400 |
Hello,
> On Apr 6, 2016, at 14:23, Mattias Andrée <address@hidden> wrote:
> [...] The rationale for this flag that it is better
> to implement it in test than as a separate command.
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=385069
>
>> On the other hand, I readily concur that "test -s
>> directory" does NOT accurately report whether the
>> directory has contents
As a temporary work-around, the following seems portable across some OSes
(gnu/linux,*BSD) and can be used as a shell function (but '-mindepth' is not in
POSIX standard):
dirempty() {
test -d "$1" \
&& test -z "$( { find "$1" -mindepth 1 2>/dev/null || echo failed ; } |
head -n1)"
}
usage is:
dirempty DIRNAME && echo empty || echo not-empty-or-error
HTH,
- assaf
- [PATCH] test: Add unary operator -E: test that a file is an empty directory, maandree, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Eric Blake, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory,
Assaf Gordon <=
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Michael Stone, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Michael Stone, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
- Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/06
[PATCH v2 1/2] test: Add unary operator -E: test that a file is an empty directory, Mattias Andrée, 2016/04/07