Package: moreutils
Version: 0.16
Severity: wishlist
Hi,
Testing a directory to be empty in bash is hackish, see
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19
The cleanest way probably is
if [ -z "$(ls -A "$dir")" ]; then
fi
Maybe we should add a small utility which does test this in a sane way.
if dirempty "$dir"; then
fi
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/dash
Kernel: Linux 2.6.17.7
Locale: LANG=de_DE.UTF-8@euro, LC_CTYPE=de_DE.UTF-8@euro (charmap=UTF-8)
Versions of packages moreutils depends on:
ii libc6 2.3.6.ds1-4 GNU C Library: Shared libraries
ii perl 5.8.8-6.1 Larry Wall's Practical Extraction
moreutils recommends no packages.
-- no debconf information
Hi,
A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'"
test -e "foo" works fine if you have the filename. If you have wildcards
it gets a bit more complicated. IMHO it would be good to have a
convenience command for this instead of using some shell magic with test
and ls.
best regards,
Erich Schubert
--
erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
Reality continues to ruin my life --- Calvin //\
Wende Dein Gesicht der Sonne zu, dann fallen die Schatten hinter Dich. V_/_
I think that by generalising beyond dirempty to include exists, you're
getting closer to a generic unix tool.
I worry though that the tool might be test(1). These seem like fairly
good candidates to add to test, especially dirempty.
--
see shy jo
Erich Schubert wrote:
> A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'"
> test -e "foo" works fine if you have the filename. If you have wildcards
> it gets a bit more complicated. IMHO it would be good to have a
> convenience command for this instead of using some shell magic with test
> and ls.
Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?
--
see shy jo
Hi Joey,
> Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?
Maybe "exists -d foo" would be nicer for this.
In many applications, "exists 'foo/*'" would do the job okay enough (if
you don't plan to rm the directory)
best regards,
Erich Schubert
--
erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
To be trusted is a greater complement than to be loved. //\
Man kann sich auch in Gesellschaft anderer einsam fühlen. Weizsäcker V_/_
Hi,
> I worry though that the tool might be test(1). These seem like fairly
> good candidates to add to test, especially dirempty.
Definitely test should have had this functionality.
However people will expect test to behave the same on all systems, so
I'm not sure adding some non-POSIX extensions to test is a good idea.
People will write scripts and use test, and then it won't work on other
systems. If it's another utility, then it will be much more obvious that
the tool might not exist on other systems.
Furthermore some shells (busybox?) might be using a built-in test, and
that wouldn't have this functionality then.
best regards,
Erich Schubert
--
erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
A man doesn't know what he knows until he knows what he doesn't know. //\
Man kann sich auch in Gesellschaft anderer einsam fühlen. Weizsäcker V_/_
Acknowledgement sent
to Michael Stummvoll <[email protected]>:
Extra info received and forwarded to list. Copy sent to Joey Hess <[email protected]>.
(Fri, 25 Nov 2011 11:15:46 GMT) (full text, mbox, link).
Package: moreutils
Version: 0.45
Followup-For: Bug #385069
Hi,
cause there didn't happen something to this topic for some years i just made a beginning. :)
Greetings,
Michael
-- System Information:
Debian Release: wheezy/sid
APT prefers testing
APT policy: (700, 'testing'), (650, 'unstable'), (600, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 3.1.0-1-686-pae (SMP w/2 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages moreutils depends on:
ii libc6 2.13-21
ii libipc-run-perl 0.90-1
ii perl 5.14.2-5
moreutils recommends no packages.
Versions of packages moreutils suggests:
ii libtime-duration-perl <none>
ii libtimedate-perl 1.2000-1
-- no debconf information
Acknowledgement sent
to Michael Cetrulo <[email protected]>:
Extra info received and forwarded to list. Copy sent to Joey Hess <[email protected]>.
(Fri, 16 Dec 2011 16:09:03 GMT) (full text, mbox, link).
I think you can achieve this with a bash function:
exists() (
shopt -s nullglob dotglob; shopt -u failglob
a=($1); [[ ${a##*/} != . && ${a##*/} != .. && -e $a ]] && return
)
you'll use it with literal globs (like you do with "find -name" for
instance) eg:
if exists 'mydir/*'; then
echo "mydir is not empty"
else
echo "mydir is empty"
fi
also notice the faq cited earlier has moved:
http://mywiki.wooledge.org/BashFAQ/004
On Thu, 7 Sep 2006 20:43:26 -0400 Joey Hess <[email protected]> wrote:
> I think that by generalising beyond dirempty to include exists, you're
> getting closer to a generic unix tool.
>
> I worry though that the tool might be test(1). These seem like fairly
> good candidates to add to test, especially dirempty.
>
> --
> see shy jo
On Mon, 28 Aug 2006 22:31:35 +0200 Erich Schubert <[email protected]> wrote:
> Package: moreutils
> Version: 0.16
> Severity: wishlist
>
> Hi,
> Testing a directory to be empty in bash is hackish, see
>
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19
>
> The cleanest way probably is
> if [ -z "$(ls -A "$dir")" ]; then
> fi
>
> Maybe we should add a small utility which does test this in a sane way.
>
> if dirempty "$dir"; then
> fi
>
> -- System Information:
> Debian Release: testing/unstable
> APT prefers unstable
> APT policy: (500, 'unstable'), (1, 'experimental')
> Architecture: i386 (i686)
> Shell: /bin/sh linked to /bin/dash
> Kernel: Linux 2.6.17.7
> Locale: LANG=de_DE.UTF-8@euro, LC_CTYPE=de_DE.UTF-8@euro (charmap=UTF-8)
>
> Versions of packages moreutils depends on:
> ii libc6 2.3.6.ds1-4 GNU C Library: Shared
libraries
> ii perl 5.8.8-6.1 Larry Wall's Practical
Extraction
>
> moreutils recommends no packages.
>
> -- no debconf information
>
>
On Sat, 02 Sep 2006 03:55:33 +0200 Erich Schubert <[email protected]> wrote:
> Hi,
> A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'"
> test -e "foo" works fine if you have the filename. If you have wildcards
> it gets a bit more complicated. IMHO it would be good to have a
> convenience command for this instead of using some shell magic with test
> and ls.
>
> best regards,
> Erich Schubert
> --
> erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
> Reality continues to ruin my life --- Calvin //\
> Wende Dein Gesicht der Sonne zu, dann fallen die Schatten hinter Dich.
V_/_
>
>
>
On Thu, 7 Sep 2006 20:45:27 -0400 Joey Hess <[email protected]> wrote:
> Erich Schubert wrote:
> > A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'"
> > test -e "foo" works fine if you have the filename. If you have wildcards
> > it gets a bit more complicated. IMHO it would be good to have a
> > convenience command for this instead of using some shell magic with test
> > and ls.
>
> Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?
>
> --
> see shy jo
On Fri, 08 Sep 2006 03:20:02 +0200 Erich Schubert <[email protected]> wrote:
> Hi Joey,
> > Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?
>
> Maybe "exists -d foo" would be nicer for this.
> In many applications, "exists 'foo/*'" would do the job okay enough (if
> you don't plan to rm the directory)
>
> best regards,
> Erich Schubert
> --
> erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
> To be trusted is a greater complement than to be loved. //\
> Man kann sich auch in Gesellschaft anderer einsam fühlen. Weizsäcker V_/_
>
>
>
On Fri, 08 Sep 2006 03:59:51 +0200 Erich Schubert <[email protected]> wrote:
> Hi,
> > I worry though that the tool might be test(1). These seem like fairly
> > good candidates to add to test, especially dirempty.
>
> Definitely test should have had this functionality.
> However people will expect test to behave the same on all systems, so
> I'm not sure adding some non-POSIX extensions to test is a good idea.
> People will write scripts and use test, and then it won't work on other
> systems. If it's another utility, then it will be much more obvious that
> the tool might not exist on other systems.
> Furthermore some shells (busybox?) might be using a built-in test, and
> that wouldn't have this functionality then.
>
> best regards,
> Erich Schubert
> --
> erich@(vitavonni.de|debian.org) -- GPG Key ID: 4B3A135C (o_
> A man doesn't know what he knows until he knows what he doesn't know. //\
> Man kann sich auch in Gesellschaft anderer einsam fühlen. Weizsäcker
V_/_
>
>
>
On Mon, 28 Aug 2006 22:31:35 +0200 Erich Schubert <[email protected]> wrote:
> Package: moreutils
> Version: 0.16
> Severity: wishlist
>
> Hi,
> Testing a directory to be empty in bash is hackish, see
>
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19
>
> The cleanest way probably is
> if [ -z "$(ls -A "$dir")" ]; then
> fi
>
> Maybe we should add a small utility which does test this in a sane way.
>
> if dirempty "$dir"; then
> fi
>
> -- System Information:
> Debian Release: testing/unstable
> APT prefers unstable
> APT policy: (500, 'unstable'), (1, 'experimental')
> Architecture: i386 (i686)
> Shell: /bin/sh linked to /bin/dash
> Kernel: Linux 2.6.17.7
> Locale: LANG=de_DE.UTF-8@euro, LC_CTYPE=de_DE.UTF-8@euro (charmap=UTF-8)
>
> Versions of packages moreutils depends on:
> ii libc6 2.3.6.ds1-4 GNU C Library: Shared
libraries
> ii perl 5.8.8-6.1 Larry Wall's Practical
Extraction
>
> moreutils recommends no packages.
>
> -- no debconf information
>
>
Acknowledgement sent
to Nicolas Schier <[email protected]>:
Extra info received and forwarded to list.
(Sat, 29 Jul 2023 20:33:03 GMT) (full text, mbox, link).
Tags: wontfix
I consider re-posting of out-dated URLs is spam. Joey (upstream
author) made his point already years ago, I think it's time to close
this bug.
Acknowledgement sent
to "Md Jafor (via Google Maps)" <[email protected]>:
Extra info received and forwarded to list. Copy sent to Nicolas Schier <[email protected]>.
(Sat, 29 Jul 2023 21:54:03 GMT) (full text, mbox, link).
Acknowledgement sent
to "Md Jafor (via Google Maps)" <[email protected]>:
Extra info received and forwarded to list. Copy sent to Nicolas Schier <[email protected]>.
(Sun, 30 Jul 2023 10:42:04 GMT) (full text, mbox, link).
Debbugs is free software and licensed under the terms of the GNU General
Public License version 2. The current version can be obtained
from https://bugs.debian.org/debbugs-source/.