From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8977 invoked by alias); 1 Sep 2010 17:28:18 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15350 Received: (qmail 16850 invoked from network); 1 Sep 2010 17:28:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Wed, 1 Sep 2010 18:01:42 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Bug Report: glob qualifier Lm-1 does not work Message-ID: <20100901180142.56a9180f@csr.com> In-Reply-To: <20100901155416.GA8509@Lancelot> References: <20100901155416.GA8509@Lancelot> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 01 Sep 2010 17:01:42.0857 (UTC) FILETIME=[5A28E390:01CB49F7] X-Scanned-By: MailControl A-06-00-00 (www.mailcontrol.com) on 10.68.0.123 On Wed, 1 Sep 2010 23:54:16 +0800 Roy Zuo wrote: > Some one just tells me that glob qualifier Lm-1 in zsh does not work, > and I can confirm it is true. Whenever you do=20 >=20 > ls *(Lm-1) >=20 > it complains "no matches found". Lm+1, Lk-1024, Lk-1, Lm-2 all work > well. The only thing that does not work is Lm-1. (Basically Bart's answer, but I added a bit more so I'll send it anyway.) It does do what it's intended to, it just doesn't do what you expect (and what it's intended to do is quite confusing if you don't know what's behind it). Something similar came up recently; as a minimum the doc could do with updating. This comment on times is also relevant to sizes: Any fractional part of the difference between the access time and the current part in the appropriate units is ignored in the comparison. For instance, =E2=80=98echo *(ah-5)=E2=80=99 would ech= o files accessed within the last five hours, while =E2=80=98echo *(ah+5)=E2=80=99= would echo files accessed at least six hours ago, as times strictly between five and six hours are treated as five hours. In other words, files "less than 1 megabyte" have to be zero. You'll see that it does indeed pick up files of zero size. The reason for this bizarre behaviour is that the same file size is used when testing for less than, equal to, or greater than the requested number. Hence *(Lm1) picks up all those files you expect to see --- the files that are 1 megabyte in size, ignoring the fractional part in the difference. The logic behind the reason is that this makes *(Lm-1), *(Lm1) and *(Lm+1) disjunct sets, as you might naively expect (until you worked out the implications). In other words, if you sort files into the three sets you're guaranteed to get all files exactly once. That's quite a useful property, although you might have thought it would make more sense to round file sizes down rather than up. If it did, I think it would be much more natural and you could probably guess that files "greater than 1 MB" needed to be 2 MB or more without having to read the instructions. It wouldn't be hard to add the other behaviour (rounding up), but I'm not sure how to control it: an option (on or off by default?), or alternative syntax (for which unfortunately < and > aren't available which is probably why it's currently - and +)? Index: Doc/Zsh/expn.yo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.118 diff -p -u -r1.118 expn.yo --- Doc/Zsh/expn.yo 22 Aug 2010 20:08:57 -0000 1.118 +++ Doc/Zsh/expn.yo 1 Sep 2010 16:56:18 -0000 @@ -2302,10 +2302,17 @@ time. ) item(tt(L)[tt(PLUS())|tt(-)]var(n))( files less than var(n) bytes (tt(-)), more than var(n) bytes (tt(PLUS())),= or -exactly var(n) bytes in length. If this flag is directly followed by a `tt= (k)' -(`tt(K)'), `tt(m)' (`tt(M)'), or `tt(p)' (`tt(P)') (e.g. `tt(Lk-50)') -the check is performed with kilobytes, megabytes, or blocks (of 512 bytes) -instead. +exactly var(n) bytes in length. + +If this flag is directly followed by a `tt(k)' (`tt(K)'), `tt(m)' +(`tt(M)'), or `tt(p)' (`tt(P)') (e.g. `tt(Lk-50)') the check is performed +with kilobytes, megabytes, or blocks (of 512 bytes) instead. In this +case a file is regarded as "exactly" the size if the file size rounded up +to the next unit is equal to the test size. Hence `tt(*LPAR()Lm1+RPAR())' +matches files from 1 byte up to 1 Megabyte inclusive. Note also that +the set of files "less than" the test size only includes files that would +not match the equality test; hence `tt(*LPAR()Lm-1+RPAR())' only matches +files of zero size. ) item(tt(^))( negates all qualifiers following it --=20 Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, = UK Member of the CSR plc group of companies. CSR plc registered in England and= Wales, registered number 4187346, registered office Churchill House, Cambr= idge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom