zsh-users
 help / color / mirror / code / Atom feed
* Maildir empty?
@ 2004-07-12  7:37 Klaus Wacker
  2004-07-12  9:43 ` DervishD
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Klaus Wacker @ 2004-07-12  7:37 UTC (permalink / raw)
  To: ZSH User List

Dear zsh, is there a zsh-internal way to find out whether a maildir is
empty? Or more generally, whether a directory tree contains no
files? The following test ($i is the pathname of the maildir):

    if [[ $(echo $i/*/* | wc -w) -eq 0 ]]

works with `setopt extendedglob nullglob', but I am sure there is some
combination of {}[]()$#@% which avoids spawning of a subshell and an
external program. 


-- 
Klaus Wacker              wacker@Physik.Uni-Dortmund.DE
Experimentelle Physik V   http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund     Tel.: +49 231 755 3587
D-44221 Dortmund          Fax:  +49 231 755 4547


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12  7:37 Maildir empty? Klaus Wacker
@ 2004-07-12  9:43 ` DervishD
  2004-07-12  9:44 ` Oliver Kiddle
  2004-07-12 10:00 ` Peter Stephenson
  2 siblings, 0 replies; 12+ messages in thread
From: DervishD @ 2004-07-12  9:43 UTC (permalink / raw)
  To: Klaus Wacker; +Cc: ZSH User List

    Hi Klaus :)

 * Klaus Wacker <wacker@physik.uni-dortmund.de> dixit:
> Dear zsh, is there a zsh-internal way to find out whether a maildir is
> empty? Or more generally, whether a directory tree contains no
> files?

    There is not any zsh-internal way to test whether a directory is
empty, you must use 'find' or the small shell function that Bart had
the kindness to give me when I needed the same as you.

    Look in the mailing list archives. I currently don't have that
function since the project I needed it for is 'sleeping'. IIRC, that
function didn't need any external program.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12  7:37 Maildir empty? Klaus Wacker
  2004-07-12  9:43 ` DervishD
@ 2004-07-12  9:44 ` Oliver Kiddle
  2004-07-12 12:41   ` Klaus Wacker
  2004-07-12 10:00 ` Peter Stephenson
  2 siblings, 1 reply; 12+ messages in thread
From: Oliver Kiddle @ 2004-07-12  9:44 UTC (permalink / raw)
  To: wacker; +Cc: ZSH User List

Klaus Wacker wrote:
> Dear zsh, is there a zsh-internal way to find out whether a maildir is
> empty? Or more generally, whether a directory tree contains no
> files? The following test ($i is the pathname of the maildir):
> 
>     if [[ $(echo $i/*/* | wc -w) -eq 0 ]]

Does this do what you want:
      if [ -z $i/*/*([1]) ]

You need to use the single brackets so that the $i/*/* is treated as a
filename expansion. The ([1]) part makes sure that only one file is
expanded.

Are you sure you didn't mean $i/**/*
You need to use **/ to search a whole directory tree.

Oliver


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12  7:37 Maildir empty? Klaus Wacker
  2004-07-12  9:43 ` DervishD
  2004-07-12  9:44 ` Oliver Kiddle
@ 2004-07-12 10:00 ` Peter Stephenson
  2004-07-12 14:17   ` Klaus Wacker
  2 siblings, 1 reply; 12+ messages in thread
From: Peter Stephenson @ 2004-07-12 10:00 UTC (permalink / raw)
  To: ZSH User List

Klaus Wacker wrote:
> Dear zsh, is there a zsh-internal way to find out whether a maildir is
> empty? Or more generally, whether a directory tree contains no
> files?

This will be fixed in 4.2.1 with the syntax `*(/^F)'.  (F) (for full)
indicates a directory with files.  (^F) indcates either not a directory
or no files.  (/^F) indicates a directory with no files.

I'll add this to the NEWS file, there are a couple of things I've
forgotten.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12  9:44 ` Oliver Kiddle
@ 2004-07-12 12:41   ` Klaus Wacker
  2004-07-12 13:22     ` DervishD
  0 siblings, 1 reply; 12+ messages in thread
From: Klaus Wacker @ 2004-07-12 12:41 UTC (permalink / raw)
  To: ZSH User List

On Mon, Jul 12, 2004 at 11:44:25AM +0200, Oliver Kiddle wrote:
> Klaus Wacker wrote:
> > Dear zsh, is there a zsh-internal way to find out whether a maildir is
> > empty? Or more generally, whether a directory tree contains no
> > files? The following test ($i is the pathname of the maildir):
> > 
> >     if [[ $(echo $i/*/* | wc -w) -eq 0 ]]
> 
> Does this do what you want:
>       if [ -z $i/*/*([1]) ]
> 
> You need to use the single brackets so that the $i/*/* is treated as a
> filename expansion. The ([1]) part makes sure that only one file is
> expanded.
> 

Thank you, that works.

> Are you sure you didn't mean $i/**/*
> You need to use **/ to search a whole directory tree.
> 

For the general case I would probably need something like
`$i/**/*(.)'. However, for maildirs, `$i/*/*' is what I need. Each
maildir contains exactly three subdirectories named tmp, new and cur,
and they contain the mail files, one per message.

-- 
Klaus Wacker              wacker@Physik.Uni-Dortmund.DE
Experimentelle Physik V   http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund     Tel.: +49 231 755 3587
D-44221 Dortmund          Fax:  +49 231 755 4547


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 12:41   ` Klaus Wacker
@ 2004-07-12 13:22     ` DervishD
  2004-07-12 14:09       ` Klaus Wacker
  0 siblings, 1 reply; 12+ messages in thread
From: DervishD @ 2004-07-12 13:22 UTC (permalink / raw)
  To: Klaus Wacker; +Cc: ZSH User List

    Hi Klaus and Oliver :)

 * Klaus Wacker <wacker@physik.uni-dortmund.de> dixit:
> > Does this do what you want:
> >       if [ -z $i/*/*([1]) ]
> > You need to use the single brackets so that the $i/*/* is treated as a
> > filename expansion.

    Why are single brackets needed here instead of [[ -z ... ]]? Why
with single brackets the $i/*/* construction is treated as a filename
expansion? Is it not using double brackets?

    Thanks :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 13:22     ` DervishD
@ 2004-07-12 14:09       ` Klaus Wacker
  2004-07-12 14:33         ` DervishD
  0 siblings, 1 reply; 12+ messages in thread
From: Klaus Wacker @ 2004-07-12 14:09 UTC (permalink / raw)
  To: ZSH User List

On Mon, Jul 12, 2004 at 03:22:21PM +0200, DervishD wrote:
>     Hi Klaus and Oliver :)
> 
>  * Klaus Wacker <wacker@physik.uni-dortmund.de> dixit:
> > > Does this do what you want:
> > >       if [ -z $i/*/*([1]) ]
> > > You need to use the single brackets so that the $i/*/* is treated as a
> > > filename expansion.
> 
>     Why are single brackets needed here instead of [[ -z ... ]]? Why
> with single brackets the $i/*/* construction is treated as a filename
> expansion? Is it not using double brackets?
> 

I can only give a partial answer. `[' is treated like any other
command, so its arguments are subject to filename expansion. The
closing `]' is basically ignored. Zsh has `[' as a built-in, but there
is also /usr/bin/[. `[[...]]' is a real shell construct with its own
syntax and rules. Don't ask me what exactly the rules are, but
essentially they are geared more towards pattern matching than file
globbing, if I remember correctly.

-- 
Klaus Wacker              wacker@Physik.Uni-Dortmund.DE
Experimentelle Physik V   http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund     Tel.: +49 231 755 3587
D-44221 Dortmund          Fax:  +49 231 755 4547


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 10:00 ` Peter Stephenson
@ 2004-07-12 14:17   ` Klaus Wacker
  2004-07-12 14:44     ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Klaus Wacker @ 2004-07-12 14:17 UTC (permalink / raw)
  To: ZSH User List

On Mon, Jul 12, 2004 at 11:00:34AM +0100, Peter Stephenson wrote:
> Klaus Wacker wrote:
> > Dear zsh, is there a zsh-internal way to find out whether a maildir is
> > empty? Or more generally, whether a directory tree contains no
> > files?
> 
> This will be fixed in 4.2.1 with the syntax `*(/^F)'.  (F) (for full)
> indicates a directory with files.  (^F) indcates either not a directory
> or no files.  (/^F) indicates a directory with no files.

Will this work recursively for subdirectories? A maildir directory is
never empty, it always contains 3 subdirectories. What I need to find
out is whether all those are empty.

-- 
Klaus Wacker              wacker@Physik.Uni-Dortmund.DE
Experimentelle Physik V   http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund     Tel.: +49 231 755 3587
D-44221 Dortmund          Fax:  +49 231 755 4547


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 14:09       ` Klaus Wacker
@ 2004-07-12 14:33         ` DervishD
  2004-07-12 18:04           ` Peter Whaite
  0 siblings, 1 reply; 12+ messages in thread
From: DervishD @ 2004-07-12 14:33 UTC (permalink / raw)
  To: Klaus Wacker; +Cc: ZSH User List

    Hi Klaus :)

 * Klaus Wacker <wacker@physik.uni-dortmund.de> dixit:
> > > > Does this do what you want:
> > > >       if [ -z $i/*/*([1]) ]
> > > > You need to use the single brackets so that the $i/*/* is treated as a
> > > > filename expansion.
> >     Why are single brackets needed here instead of [[ -z ... ]]? Why
> > with single brackets the $i/*/* construction is treated as a filename
> > expansion? Is it not using double brackets?
> I can only give a partial answer. `[' is treated like any other
> command, so its arguments are subject to filename expansion.

    Yes, I know, it happens even with the builtin '['.

>`[[...]]' is a real shell construct with its own syntax and rules.
> Don't ask me what exactly the rules are, but essentially they are
> geared more towards pattern matching than file globbing, if I
> remember correctly.

    OK, that's a good explanation :)) Thanks a lot!

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 14:17   ` Klaus Wacker
@ 2004-07-12 14:44     ` Peter Stephenson
  0 siblings, 0 replies; 12+ messages in thread
From: Peter Stephenson @ 2004-07-12 14:44 UTC (permalink / raw)
  To: wacker; +Cc: ZSH User List

Klaus Wacker wrote:
> On Mon, Jul 12, 2004 at 11:00:34AM +0100, Peter Stephenson wrote:
> > Klaus Wacker wrote:
> > > Dear zsh, is there a zsh-internal way to find out whether a maildir is
> > > empty? Or more generally, whether a directory tree contains no
> > > files?
> > 
> > This will be fixed in 4.2.1 with the syntax `*(/^F)'.  (F) (for full)
> > indicates a directory with files.  (^F) indcates either not a directory
> > or no files.  (/^F) indicates a directory with no files.
> 
> Will this work recursively for subdirectories? A maildir directory is
> never empty, it always contains 3 subdirectories. What I need to find
> out is whether all those are empty.

*/*(N/^F) or **/*(N/^F) if you really mean mean `recursive'.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 14:33         ` DervishD
@ 2004-07-12 18:04           ` Peter Whaite
  2004-07-13 18:28             ` Dan Nelson
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Whaite @ 2004-07-12 18:04 UTC (permalink / raw)
  To: ZSH User List

DervishD <raul@pleyades.net> wrote:
>
> > I can only give a partial answer. `[' is treated like any other
> > command, so its arguments are subject to filename expansion.
>

It used to be that /bin/[ was a link to /bin/test,  which is why
/bin/test still swallows a trailing ].  Now wasn't that clever!

-- 
Peter Whaite (http://whaite.ca)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Maildir empty?
  2004-07-12 18:04           ` Peter Whaite
@ 2004-07-13 18:28             ` Dan Nelson
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Nelson @ 2004-07-13 18:28 UTC (permalink / raw)
  To: Peter Whaite; +Cc: ZSH User List

In the last episode (Jul 12), Peter Whaite said:
> DervishD <raul@pleyades.net> wrote:
> > > I can only give a partial answer. `[' is treated like any other
> > > command, so its arguments are subject to filename expansion.
> 
> It used to be that /bin/[ was a link to /bin/test,  which is why
> /bin/test still swallows a trailing ].  Now wasn't that clever!

Getting off-topic :)  but if your test eats a trailing bracket it's a
bug.  When test and [ are hardlinked, the program must check argv[0]
and only eat a right-bracket if it was run as [.

$ ls -la =test =\[
814 -r-xr-xr-x  2 root  wheel  93948 Nov 26  2003 /bin/[
814 -r-xr-xr-x  2 root  wheel  93948 Nov 26  2003 /bin/test
$ command test "]" ; echo $?
0
$ command "[" "]" ; echo $?
1


  SYNOPSIS
     test expression
     [ expression ]

     The test utility evaluates the expression and, if it evaluates to
     true, returns a zero (true) exit status; otherwise it returns 1
     (false).  If there is no expression, test also returns 1 (false).
  ...
     The following primaries are used to construct expression:
  ...
     _string_        True if _string_ is not the null string.

-- 
	Dan Nelson
	dnelson@allantgroup.com


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-07-13 19:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-12  7:37 Maildir empty? Klaus Wacker
2004-07-12  9:43 ` DervishD
2004-07-12  9:44 ` Oliver Kiddle
2004-07-12 12:41   ` Klaus Wacker
2004-07-12 13:22     ` DervishD
2004-07-12 14:09       ` Klaus Wacker
2004-07-12 14:33         ` DervishD
2004-07-12 18:04           ` Peter Whaite
2004-07-13 18:28             ` Dan Nelson
2004-07-12 10:00 ` Peter Stephenson
2004-07-12 14:17   ` Klaus Wacker
2004-07-12 14:44     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).