zsh-users
 help / color / mirror / code / Atom feed
* var expansion in glob pattern?
@ 2002-03-23 18:56 Sven Guckes
  2002-03-23 19:36 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Guckes @ 2002-03-23 18:56 UTC (permalink / raw)
  To: ZShell Users

Most of my mail folders are small -
usually just questions and
answers about some program.

so I tried to run a quick statistics
on my Mail directory using the zsh
and its file globbing by size:

  $ cd ~/Mail
  $ for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
      ls *(.Lk-$i)|wc -l
    end
  zsh: parse error near `end'

as you can see, it failed.
i suppose there is no variable
substitution inside globbing brackets.
but I'm sure there must be a way.
any hints?

Sven


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

* Re: var expansion in glob pattern?
  2002-03-23 18:56 var expansion in glob pattern? Sven Guckes
@ 2002-03-23 19:36 ` Bart Schaefer
  2002-03-23 19:54   ` Bart Schaefer
  2002-03-24  0:12   ` var expansion in glob pattern? - s/end/done/ ! Sven Guckes
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2002-03-23 19:36 UTC (permalink / raw)
  To: Sven Guckes, zsh-users

On Mar 23,  7:56pm, Sven Guckes wrote:
} Subject: var expansion in glob pattern?
}
}   $ for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
}       ls *(.Lk-$i)|wc -l
}     end
}   zsh: parse error near `end'

You need "done" rather than "end", there.  There's nothing wrong with
the glob expression -- except that passing it as the argument to "ls"
may do the wrong thing when there are no matches at all.

Of course note that the files smaller than 50k includes all the files
smaller than 45k, and so on ... so I'd try:

    j=0
    for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
      print ${(l:3:)i}k : "${#${(f)$(print -l *(N.Lk-${i}Lk+${j}))}}"
      ((j=i-1))
    done
    print Rest : "${#${(f)$(print -l *(N.Lk+${j}))}}"

Detailed explanation available upon request.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: var expansion in glob pattern?
  2002-03-23 19:36 ` Bart Schaefer
@ 2002-03-23 19:54   ` Bart Schaefer
  2002-03-24  0:19     ` Sven Guckes
  2002-03-24  0:12   ` var expansion in glob pattern? - s/end/done/ ! Sven Guckes
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2002-03-23 19:54 UTC (permalink / raw)
  To: Sven Guckes, zsh-users

On Mar 23,  7:36pm, Bart Schaefer wrote:
}
} except that passing [the glob expression] as the argument to "ls"
} may do the wrong thing when there are no matches at all.

Hmm, just noticed that my solution is also off when there are no matches,
because "${#${(f)...}}" didn't behave the way I expected on empty string
(returns 1 rather than 0).  So really:

    j=0
    for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
      print ${(l:3:)i}k : "$[${#${(f)$(print -l x *(N.Lk-${i}Lk+${j}))}}-1]"
      ((j=i-1))
    done
    print Rest : "$[${#${(f)$(print -l x *(N.Lk+${j}))}}-1]"

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: var expansion in glob pattern? - s/end/done/ !
  2002-03-23 19:36 ` Bart Schaefer
  2002-03-23 19:54   ` Bart Schaefer
@ 2002-03-24  0:12   ` Sven Guckes
  1 sibling, 0 replies; 5+ messages in thread
From: Sven Guckes @ 2002-03-24  0:12 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer <schaefer@brasslantern.com> [2002-03-23 19:36]:
> On Mar 23,  7:56pm, Sven Guckes wrote:
> }   $ for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
> }       ls *(.Lk-$i)|wc -l
> }     end
> }   zsh: parse error near `end'
> 
> You need "done" rather than "end", there.

  $ for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
      ls *(.Lk-$i)|wc -l
   done
      9
    211
    642
   1298
   2015
   3331
   3882
   4188
   4365
   4493
   4595
   4670
   4595
   4670
   4716
   4757

now it works!  :-)

> There's nothing wrong with the glob expression --
> except that passing it as the argument to "ls" may do
> the wrong thing when there are no matches at all.

good point!

> Of course note that the files smaller than 50k
> includes all the files smaller than 45k, and so on ...

yep, that's a feature. :-)

Sven


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

* Re: var expansion in glob pattern?
  2002-03-23 19:54   ` Bart Schaefer
@ 2002-03-24  0:19     ` Sven Guckes
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Guckes @ 2002-03-24  0:19 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer <schaefer@brasslantern.com> [2002-03-23 19:54]:
> j=0
> for i in 1 2 3 4 5 10 15 20 25 30 35 40 35 40 45 50; do
>   print ${(l:3:)i}k : "$[${#${(f)$(print -l x *(N.Lk-${i}Lk+${j}))}}-1]"
>   ((j=i-1))
> done
> print Rest : "$[${#${(f)$(print -l x *(N.Lk+${j}))}}-1]"

(Bart's print) (not in output)
    1k : 0     .
    2k : 202   .**
    3k : 431   .****
    4k : 656   .******.
    5k : 717   .*******
   10k : 1316  .*************
   15k : 551   .*****.
   20k : 306   .***
   25k : 177   .*.
   30k : 128   .*
   35k : 102   .*
   40k : 75    ..
   35k : 0     .
   40k : 75    ..
   45k : 46    ..
   50k : 41    .
  Rest : 502   .*****

thanks, Bart! :-)

Sven  [reading up on "print"
       and glob patterns]


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

end of thread, other threads:[~2002-03-24  0:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-23 18:56 var expansion in glob pattern? Sven Guckes
2002-03-23 19:36 ` Bart Schaefer
2002-03-23 19:54   ` Bart Schaefer
2002-03-24  0:19     ` Sven Guckes
2002-03-24  0:12   ` var expansion in glob pattern? - s/end/done/ ! Sven Guckes

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).