[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: |
Mattias Andrée |
Subject: |
Re: [PATCH] test: Add unary operator -E: test that a file is an empty directory |
Date: |
Wed, 6 Apr 2016 22:10:26 +0200 |
User-agent: |
Claws Mail |
On Wed, 6 Apr 2016 21:57:11 +0200
Mattias Andrée <address@hidden> wrote:
> On Wed, 6 Apr 2016 15:36:29 -0400
> Assaf Gordon <address@hidden> wrote:
>
> >
> > 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
Of course, you need -- too.
> > || echo failed ; } | head -n1)" }
> >
> > usage is:
> >
> > dirempty DIRNAME && echo empty || echo
> > not-empty-or-error
>
> It is too complicated and you need to use find "$1/",
> not find "$1". But you can use:
>
> test -d "$1" && python - "$1" <<EOF
> import os, sys
> sys.exit(1 if len(os.listdir(sys.argv[1])) else 0)
> EOF
>
> or
>
> test -d "$1" && test -z "$(ls -A -- "$1/")"
We have now demonstrated that attempts to
implement this functionally in shell script
without -E is prone to errors in addition
to being messy.
pgpPlbsFBUkXt.pgp
Description: OpenPGP digital signature
- [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, 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 <=
- 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