Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: globbing in conditional expressions



# d.s@xxxxxxxxxxxxxxxxxx / 2014-05-15 09:14:58 +0000:
> Roman Neuhauser wrote on Wed, May 14, 2014 at 23:09:23 +0200:
> > wonderful, thank you!
> 
> You're welcome, but beware: the code doesn't work properly in all cases,
> e.g., as Bart suspected, [[ -m **/*attr.yo(/) ]] (in a built zsh source
> tree) false positives.

understood, still, thanks a lot for kickstarting it.

> > i'm trying to think of a situation where [[ -m $pat ]] && mangle $REPLY
> > would be useful for something other than foot-shooting... any ideas?
> 
> Well, there is:
> 
>     while [[ -m $pat ]] ;
>       # Suppose -m implicitly sets $REPLY to a matching filename ...
>       () { mangle $1 && rm $1 } $REPLY
> 
> Since the filename returned would be the first in readdir() order, this
> could result in starvation (some files never reaching mangle()) unless
> the underlying filesystem's readdir() provides more guarantees than the
> POSIX readdir() does.

that's the foot-shooting part. :)  the above imo screams for change to

  for f in $~pat; do
    mangle $f && rm $f
  done

globbing can provide for ordering (like if you needed the oldest or
largest file).

if you need a random file, shortcircuiting readdir() is not the answer.

-- 
roman



Messages sorted by: Reverse Date, Date, Thread, Author